Luhn-10 Algorithm

[back]

Detection of Typing errors at the client to off-load the server's work.

Credit Card numbers are typically between 13-16 digits in length, and can be checked to determine if they are a proper number sequence. This check does not determine the validity of the account, but only that the presented number could be a live account.

To check, each digit is alternately multiplied by 2 and 1. If the
result of the multiplication yields a two digit number (e.g., 2
*9=18), then add the two digits (e.g.,  18 become 1 + 8 = 9), record the generated digit stream.  Sum all the recorded digits. When the all the digits have been multiplied and the stream is summed, the final result must be zero modulo 10 (i.e., divisible by 10 ).

Example, could 1234 be a Credit Card number?
2 * (1) + 1 *(2) + 2 * (3) + 1 *(4) = 14, 

but 14 / 10 = 1.4  <--- it is not a valid number.

Example, could 544213 be a Credit Card number?
1 (5) + 2(4) + 1(2) + 2(1) + 1(3) =  20, 

and  20/10 = 2 <--- it is a valid sequence.


Actual Credit Card have prefixes that are unique to each card, below is a partial table of some prefixes.

Card Type Prefix Length
MASTERCARD51-5516
VISA413, 16
AMEX34, 3715
Diners Club/
Carte Blanche
300-305
36, 38
14
Discover601116
JCB316
JCB2131, 180015