This is the old MovableType blog. To enter the new blog visit the home page.

March 26, 2007

E-commerce > Credit Card Checksum Validation

This is a very good explanation of credit card checksums. Credit card numbers aren't serial numbers. You can't just change one number on your card and get a valid credit card number.

Shopping cart software can run a checksum on your card number to see if it's a valid number. That way it can reject a mis-typed credit card number without communicating with the credit card company's computers. That doesn't prove the credit card account is valid - it just proves that the credit card number is plausible. A single mis-typed or transposed numbers will result in an invalid card number which most shopping carts will reject instantly. (If you make two mistakes, it's possible they'll cancel each other out and result in a plausible number that passes a checksum. Not likely, but possible.)

This is a nice summary of the lengths and initial digits of major credit cards.

Card Type PrefixLength Check digit algorithm
MasterCard51-5516 mod 10
VISA413, 16 mod 10
American Express34
37
15 mod 10
Diners Club/
Carte Blanche
300-305
36
38
14mod 10
Discover601116 mod 10
enRoute2014
2149
15any
JCB316mod 10
JCB2131
1800
15 mod 10

Using those characteristics, Some shopping carts (Google Checkout is one) can automatically set your credit card type when you enter your card number.

A legitimate Visa number that's easy to remember is 4111 1111 1111 1111. When we set up our credit card merchant account that's the number they gave us to use for testing. The credit card company would give a successful response to our shopping cart for purchases made with that card number, but wouldn't actually process the charges.

Here's an online credit card number validator with examples of valid numbers, and here's a JavaScript credit card validator.

Posted by lesjones | TrackBack



Comments

Terms of Use