The CreditCardValidator class validates that a credit card number is the correct length, has the correct prefix, and passes the Luhn mod10 algorithm for the specified card type. This validator does not check whether the credit card is an actual active credit card account.
You can specify the input to the CreditCardValidator in two ways:
- Use the
cardNumberSource
andcardNumberProperty
properties to specify the location of the credit card number, and thecardTypeSource
andcardTypeProperty
properties to specify the location of the credit card type to validate. -
Use the
source
andproperty
properties to specify a single Object.The Object should contain the following fields:
-
cardType
- Specifies the type of credit card being validated. -
cardNumber
- Specifies the number of the card being validated.
-
To perform the validation, it uses the following guidelines:
Length:
- Visa: 13 or 16 digits
- MasterCard: 16 digits
- Discover: 16 digits
- American Express: 15 digits
- Diners Club: 14 digits or 16 digits if it also functions as MasterCard
Prefix:
- Visa: 4
- MasterCard: 51 to 55
- Discover: 6011
- American Express: 34 or 37
- Diners Club: 300 to 305, 36 or 38, 51 to 55
See also:
Static methods
staticvalidateCreditCard(validator:CreditCardValidator, value:Dynamic, baseField:String):Array<ValidationResult>
Convenience method for calling a validator. Each of the standard Flex validators has a similar convenience method.
Parameters:
validator | The CreditCardValidator instance. |
---|---|
value | A field to validate, which must contain
the |
baseField | Text representation of the subfield
specified in the value parameter.
For example, if the |
Returns:
An Array of ValidationResult objects, with one ValidationResult object for each field examined by the validator.
See also:
Constructor
Variables
cardNumberListener:IValidatorListener
The component that listens for the validation result
for the card number subfield.
If none is specified, use the value specified
to the cardNumberSource
property.
cardNumberProperty:String
Name of the card number property to validate. This attribute is
optional, but if you specify the cardNumberSource
property,
you should also specify either cardNumberProperty
or
cardNumberValueFunction
as well.
See also:
cardNumberValueFunction
cardNumberSource:Dynamic
Object that contains the value of the card number field.
If you specify a value for this property, you must also specify
a value for either the cardNumberProperty
property or the
cardNumberValueFunction
property.
Do not use this property if you set the source
and property
(or valueFunction
) properties.
See also:
cardNumberProperty
cardNumberValueFunction
cardTypeListener:IValidatorListener
The component that listens for the validation result
for the card type subfield.
If none is specified, then use the value
specified to the cardTypeSource
property.
cardTypeProperty:String
Name of the card type property to validate. This property is optional,
but if you specify the cardTypeSource
property, you should specify
either cardTypeProperty
or cardTypeValueFunction
as well.
See also:
cardTypeValueFunction
cardTypeSource:Dynamic
Object that contains the value of the card type field.
If you specify a value for this property, you must also specify
a value for either the cardTypeProperty
property or the
cardTypeValueFunction
property.
Do not use this property if you set the source
and property
(or valueFunction
) properties.
See also:
cardTypeProperty
cardTypeValueFunction
wrongLengthError:String
Error message when the cardNumber
field contains the wrong
number of digits for the specified credit card type.
wrongTypeError:String
Error message the cardType
field contains an invalid credit card type.
You should use the predefined constants for the cardType
field:
cardNumberValueFunction:() ‑> Dynamic
A function that returns the day value to validate. It's recommended to
use cardNumberValueFunction
instead of cardNumberProperty
because
reflection is used with cardNumberProperty
, which could result in
issues if Dead Code Elimination (DCE) is enabled.
cardTypeValueFunction:() ‑> Dynamic
A function that returns the day value to validate. It's recommended to
use cardTypeValueFunction
instead of cardTypeProperty
because
reflection is used with cardTypeProperty
, which could result in issues
if Dead Code Elimination (DCE) is enabled.