Usability

CREDIT

CARD

VALIDA-

TION

Credit card verification

Checking the validity of credit-card numbers has two dimensions. On one side, we want to identify the card issuer and confirm for the user that the number they’ve typed is correct. On the other, we have to validate the number—the key element—before initializing the electronic payment process.

Credit card validation - Responsive Checkout


How to tell if a credit-card number is correct?


Rejection of a payment due to a wrong credit-card number could result in the user abandoning their cart. The formats of credit-card numbers are strictly specified in the ISO/IEC 7812 standard. Unfortunately, this format is not explicit, and it is not possible to identify all card issuers and types. 

There are, however, several informal conventions for the most popular issuers. For example:

• If the number starts with a 4, then it’s a Visa card.

• If the first two numbers are between 51 and 55, then it’s a MasterCard.

Interestingly, credit-card numbers can have from 13 to 16 characters. They also contain a “control”: The numbers that end this control string verify the validity of the credit-card number.


Meet the Luhn algorithm


The Luhn algorithm is used to check whether a credit-card number has been typed correctly. Briefly, you would multiply each odd number in the string by 2, then add up all of the numbers and add it to the even numbers. If the sum of the new string is divisible by 10, then the credit-card number can be considered “correct,” mathematically speaking.

If the formula checks out, then the probability that the user has typed the right number is much higher. Otherwise, any mistakes can be quickly identified, and the user can be asked to correct them before the data is sent to the online payment provider.


List of articles