forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathencodeCreditCardNumber.as
More file actions
27 lines (27 loc) · 939 Bytes
/
encodeCreditCardNumber.as
File metadata and controls
27 lines (27 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package utils.validation
{
/**
* Encode a credit card number as a string and encode all digits except the
* last <code>digitsShown</code>.
*
* @param strNumber credit card number as string
* @param digitsShown display this many digits at the end of the card number for security purposes
* @param encodeChar optional encoding character to use instead of default '*'
*
* @example
* <listing version="3.0">
* trace(CreditCardValidator.EncodeNumber("1234567890123456")); // ************3456
* trace(CreditCardValidator.EncodeNumber("1234567890123456", 5, "x")); // xxxxxxxxxxx23456
* </listing>
*/
public function encodeCreditCardNumber(strNumber:String, digitsShown:uint = 4, encodeChar:String = "*"):String
{
var encoded:String = "";
for (var i:Number = 0; i < strNumber.length - digitsShown; i++)
{
encoded += encodeChar;
}
encoded += strNumber.slice(-digitsShown);
return encoded;
}
}