Credit card Number validation

Credit card validations are very important when it comes to E-commerce.

Most of the time your clearing house will validate the number and return an error message if something went wrong. If your clearing house does the validation it means that the order has already been closed and if your user typed the wrong credit card number he might have to go through the whole sale process again (choose items, fill out credit the card form, perhaps fill out the wrong credit card number again).

If the user is not aware of the error, perhaps after two attempts he’ll quit trying and the sale will be lost.

Let’s think in USABILITY.

If your user realizes he’s typing the wrong credit card number from the moment he’s filling the form, he won’t have to deal with the clearing house coming back with a rejected transaction.

How do you validate a credit card number?

You’ll have to check 2 thing:

  1. Credit card number type 
  2. Luhn’s algorithm

Both of them are important to get a correct validation for you credit card number. Both will help you give great hints to your user in case he’s typing an incorrect credit card number.

Credit Card Type

Most of credit card numbers are built with 4 blocks of information:

  • MII (Major Industry Identifier)
  • IIN (Issuer Identification Number)
  • Person’s account number
  • Check digit

So basically you can start your validations from the very first typed digit and by the time your user has typed the first six digits you can clearly identify the credit card’s issuer. For more information go to:

http://en.wikipedia.org/wiki/Credit_card_numbers

You’ll see that different industries have a specific IIN assigned to them.

Luhn’s Algorithm

The Luhn’s Algorithm is used to verify that the numbers sequence is valid by doing a checksum of the credit card’s number.

The details of the algorithm can be found here:

http://en.wikipedia.org/wiki/Luhn_algorithm

The best credit card validation would check both type and check digit to be correct. This is great because perhaps the user types a CCN for a Maestro card while his card is VISA; by means of switching an image the customer may realize something is wrong.

This validations can be done both in client and server side scripts before sending data to the clearing house.

Comments are closed.