Credit Card Check Digit Validation
Credit Card Check Digit Validation
Credit Card Check Digit Validation
When a user has keyed in a credit card number (or scanned it) and you want to validate it before sending it
our for debit authorization.
When issuing cards, say an affinity card, you might want to add a check digit using the MOD 10 method.
Check digit
CARD TYPE Prefix Length algorithm
MASTERCARD 51-55 16 mod 10
VISA 4 13, 16 mod 10
34
AMEX 15 mod 10
37
300-305
Diners Club/
36 14 mod 10
Carte Blanche
38
Discover 6011 16 mod 10
2014
enRoute 15 any
2149
JCB 3 16 mod 10
2131
JCB 15 mod 10
1800
Step 1: Double the value of alternate digits of the primary account number beginning with the second digit from
the right (the first right--hand digit is the check digit.)
Step 2: Add the individual digits comprising the products obtained in Step
Go 1JUL
to each
SEPofOCT
the unaffected👤digits
⍰ in
http://www.beachnet.com/~hstiles/cardtype.html
the original number. ❎
672 captures 01 f 🐦
17 Jan 1999 - 19 Aug 2020 2007 2008 2009 ▾ About this capture
Step 3: The total obtained in Step 2 must be a number ending in zero (30, 40, 50, etc.) for the account number to
be validated.
Step 1:
4 9 9 2 7 3 9 8 7 1 6
x2 x2 x2 x2 x2
------------------------------
18 4 6 16 2
The great folks at ICVERIFY are the original source of this data, I only formatted it in HTML.
If you are in the market, I wrote a set of FoxPro modules for Windows/Dos that interface nicely with ICVERIFY
in a multi-user LAN setup. You just set up ICVERIFY on a single station, and all stations on the LAN can
authorize credit cards with a single FOXBASE function call. Of course, you have to license ICVERIFY by the
node, but it is very reasonable. I also wrote a couple of simple functions to perform pre-authorization, card
screening, etc.
Here is a Microsoft Excel worksheet that will validate a number for you (useful for understanding the algorithm,
it is in a .ZIP compressed format)
Horace Vallas made a NeoWebScript (Tcl really) procedure that implements it.
Check it out at https://enterprise.neosoft.com/secureforms/hav/
Because I get at least a letter a week regarding this routine, here are some additional helpful notes:
1. have started with the rightmost digit (including the check digit) (figure odd and even based upon the
rightmost digit being odd, regardless of the length of the Credit Card.) ALWAYS work right to left.
2. the check digit counts as digit #1 (assuming that the rightmost digit is the check digit) and is not doubled
3. double every second digit (starting with digit # 2 from the right)
4. remember that when you double a number over 4, (6 for example) you don't add the result to your total,
but rather the sum of the digits of the result (in the above example 6*2=12 so you would add 1+2 to your
total (not 12).
5. always include the Visa or M/C/ prefix.