• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 21. Using JavaScript to Create S... > Verifying Well-Formed Credit Card Nu...

Verifying Well-Formed Credit Card Numbers

The only way to completely verify the validity of a credit card number is through a Web server specifically set up to handle credit card transactions. However, you can apply some checks at the client-side, using JavaScript, that enable you to determine whether the number is well formed. A well-formed number is one that could be a valid number for that type of credit card. Passing the test for being well formed does not mean that the number is from a good credit card; failing the test, however, does mean that the number can't be from a good card.

You can apply two easy tests using JavaScript at the client-side. These tests enable you to determine whether a credit card number for a given card type is well formed. The first is to check the prefix (the first one to four numbers) and the length—each major credit card type has a given prefix and length. Second, most algorithms are encoded with a "check digit." This digit is added to the number and can also be determined from the rest of the digits in the card by using a simple algorithm. Therefore at the client-side, you can apply the algorithm to generate the check digit and compare it to the digit actually present. If they do not match, the number is not well formed.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint