CREDIT CARD VALIDATOR
Rev 2: December 2004
Visa 4111 1111 1111 1111 MasterCard 5500 0000 0000 0004 AmEx 3400 0000 0000 009 Discover 6011 0000 0000 0012
All credit cards include certain self-verifying features. Card numbers have fixed lengths (15 digits for American Express, and 16 digits for MasterCard, Visa and Discover), and each card type only permits a limited range of valid initial digits or prefixes. In addition, card numbers contain a "check digit" which is used to ensure that that only certain number combinations are valid.
The automated expiration year select function initYearSelect(f) is called as an onload event from the document body tag. It accepts one parameter (f) which is a reference to the form containing the select:
The expiration year select will populate with a list of two digit expiration years (YY) from the current year to the current year plus 10.
The credit card validation subroutine checknumber() is called as the return value of the form's onsubmit event handler and accepts a single parameter which is a reference to the form containing the credit card controls, or simply the keyword this:
<FORM action="example.html" onsubmit="return checknumber(this)>
If the results of checknumber() are false (one or more errors), submission will abort and an alert dialog will launch indicating the nature of each error identified by the scripts.
Integrating With Standard Validator
The credit card validation subroutine can be integrated with the standard forms validator by (1) inserting the credit card validator functions in the head of the document containing the form; (2) including the credit card form controls in the form section containing the other validated controls; and (3) adding the following line to Validate()
Note that in this case you do not need to make a separate call to checknumber() from the form's onsubmit attribute.
< CODEBASE | TOP^ | MAINPAGE >
Text & Design By Tony Pisarra
© SophiaKnows 1998-2004