(Preview)
Package | mx.validators |
Class | public class CreditCardValidator |
Inheritance | CreditCardValidator ![]() ![]() ![]() |
Language Version: | ActionScript 3.0 |
Product Version: | Flex 3 |
Runtime Versions: | Flash Player 9, AIR 1.1 |
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.In MXML, use the values:
"American Express"
,"Diners Club"
,"Discover"
,"MasterCard"
, or"Visa"
.In ActionScript, use the static constants
CreditCardValidatorCardType.MASTER_CARD
,CreditCardValidatorCardType.VISA
, orCreditCardValidatorCardType.AMERICAN_EXPRESS
CreditCardValidatorCardType.DISCOVER
, orCreditCardValidatorCardType.DINERS_CLUB
. -
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
- Visa: 4
- MasterCard: 51 to 55
- Discover: 6011
- American Express: 34 or 37
- Diners Club: 300 to 305, 36 or 38, 51 to 55

The <mx:CreditCardValidator>
tag
inherits all of the tag attributes of its superclass,
and adds the following tag attributes:
<mx:CreditCardValidator allowedFormatChars=" -" cardNumberListener="Object specified by cardNumberSource" cardNumberProperty="No default" cardNumberSource="No default" cardTypeListener="Object specified by cardTypeSource" cardTypeProperty="No default" cardTypeSource="No default" invalidCharError= "Invalid characters in your credit card number. (Enter numbers only.)" invalidNumberError="The credit card number is invalid." noNumError="No credit card number is specified." noTypeError="No credit card type is specified or the type is not valid." wrongLengthError="Your credit card number contains the wrong number of digits." wrongTypeError="Incorrect card type is specified." />
More examples
Related API Elements
Public Properties
Property | Defined By | ||
---|---|---|---|
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance. | Object |
Protected Properties
Public Methods
Method | Defined By | ||
---|---|---|---|
![]() | addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener
receives notification of an event. | EventDispatcher | |
![]() |
Dispatches an event into the event flow. | EventDispatcher | |
![]() |
Checks whether the EventDispatcher object has any listeners registered for a specific type
of event. | EventDispatcher | |
![]() |
Indicates whether an object has a specified property defined. | Object | |
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | |
![]() |
Indicates whether the specified property exists and is enumerable. | Object | |
![]() |
Removes a listener from the EventDispatcher object. | EventDispatcher | |
![]() |
Sets the availability of a dynamic property for loop operations. | Object | |
![]() |
Returns the string representation of this object, formatted according to locale-specific conventions. | Object | |
![]() |
Returns the string representation of the specified object. | Object | |
![]() |
Returns the primitive value of the specified object. | Object | |
![]() |
Checks whether an event listener is registered with this EventDispatcher object or any of
its ancestors for the specified event type. | EventDispatcher |
Protected Methods
Method | Defined By |
---|
Protected Constants
Property Detail
Constructor Detail
Method Detail
Examples How to use this example
CreditCardValidatorExample.mxml
<?xml version="1.0" encoding="utf-8"?> <!-- Simple example to demonstrate the CreditCardValidator. --> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"> <fx:Script> import mx.controls.Alert; </fx:Script> <fx:Declarations> <!-- Define model for the credit card data. --> <fx:Model id="creditcard"> <card> <cardType>{cardTypeCombo.selectedItem.data}</cardType> <cardNumber>{cardNumberInput.text}</cardNumber> </card> </fx:Model> <mx:CreditCardValidator id="ccV" cardTypeSource="{creditcard}" cardTypeProperty="cardType" cardNumberSource="{creditcard}" cardNumberProperty="cardNumber" trigger="{myButton}" triggerEvent="click" cardTypeListener="{cardTypeCombo}" cardNumberListener="{cardNumberInput}" valid="Alert.show('Validation Succeeded!');"/> </fx:Declarations> <s:Panel title="CreditCardValidator Example" width="75%" height="75%" horizontalCenter="0" verticalCenter="0"> <mx:Form id="creditCardForm" left="10" right="10" top="10" bottom="10"> <mx:FormItem label="Card Type"> <mx:ComboBox id="cardTypeCombo"> <mx:dataProvider> <fx:Object label="American Express" data="American Express"/> <fx:Object label="Diners Club" data="Diners Club"/> <fx:Object label="Discover" data="Discover"/> <fx:Object label="MasterCard" data="MasterCard"/> <fx:Object label="Visa" data="Visa"/> </mx:dataProvider> </mx:ComboBox> </mx:FormItem> <mx:FormItem label="Credit Card Number"> <s:TextInput id="cardNumberInput"/> </mx:FormItem> <mx:FormItem> <s:Button id="myButton" label="Check Credit"/> </mx:FormItem> </mx:Form> </s:Panel> </s:Application>
Wed Nov 21 2018, 06:34 AM -08:00