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:

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 cardType and cardNumber fields.

baseField

Text representation of the subfield specified in the value parameter. For example, if the value parameter specifies value.date, the baseField value is "date".

Returns:

An Array of ValidationResult objects, with one ValidationResult object for each field examined by the validator.

See also:

Constructor

new()

Constructor.

Variables

allowedFormatChars:String

The set of formatting characters allowed in the cardNumber field.

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:

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:

invalidCharError:String

Error message when the cardNumber field contains invalid characters.

invalidNumberError:String

Error message when the credit card number is invalid.

noNumError:String

Error message when the cardNumber field is empty.

noTypeError:String

Error message when the cardType field is blank.

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.

Inherited Variables

Defined by Validator

enabled:Bool

Setting this value to false will stop the validator from performing validation. When a validator is disabled, it dispatch no events, and the validate() method returns null. *

listener:Dynamic

Specifies the validation listener.

If you do not specify a listener, Flex uses the value of the source property. After Flex determines the source component, it changes the border color of the component, displays an error message for a failure, or hides any existing error message for a successful validation.

property:String

A String specifying the name of the property of the source object that contains the value to validate. Setting property is optional, but if you specify source, you should set a value for either property or valueFunction as well.

Reading the property uses reflection, which may not work if Dead Code Elimination (DCE) is enabled. The property property is included for backwards compatibility with the Flex API, but the new valueFunction is now recommended instead.

See also:

  • valueFunction

required:Bool

If true, specifies that a missing or empty value causes a validation error.

requiredFieldError:String

Error message when a value is missing and the required property is true.

source:Dynamic

Specifies the object containing the property to validate. Set this to an instance of a component or a data model. You use data binding syntax in MXML to specify the value. This property supports dot-delimited Strings for specifying nested properties.

If you specify a value to the source property, then you should specify a value to either the property property or the valueFunction property as well. The source property is optional.

See also:

  • property

  • valueFunction

trigger:IEventDispatcher

Specifies the component generating the event that triggers the validator. If omitted, by default Flex uses the value of the source property. When the trigger dispatches a triggerEvent, validation executes.

triggerEvent:String

Specifies the event that triggers the validation. If omitted, Flex uses the valueCommit event. Flex dispatches the valueCommit event when a user completes data entry into a control. Usually this is when the user removes focus from the component, or when a property value is changed programmatically. If you want a validator to ignore all events, set triggerEvent to the empty string ("").

valueFunction:() ‑> Dynamic

A function that returns the value to validate. It's recommended to use valueFunction instead of property because reflection is used with property, which could result in issues if Dead Code Elimination (DCE) is enabled.

Inherited Methods

Defined by Validator

@:value({ suppressEvents : false, value : null })validate(?value:Dynamic, suppressEvents:Bool = false):ValidationResultEvent

Performs validation and optionally notifies the listeners of the result.

Parameters:

value

Optional value to validate. If null, then the validator uses the source and property properties to determine the value. If you specify this argument, you should also set the listener property to specify the target component for any validation error messages.

suppressEvents

If false, then after validation, the validator will notify the listener of the result.

Returns:

A ValidationResultEvent object containing the results of the validation. For a successful validation, the ValidationResultEvent.results Array property is empty. For a validation failure, the ValidationResultEvent.results Array property contains one ValidationResult object for each field checked by the validator, both for fields that failed the validation and for fields that passed. Examine the ValidationResult.isError property to determine if the field passed or failed the validation.

See also: