Credit Card Validation – Angular Directive

Codepen url – http://codepen.io/sandeep821/pen/BLdVgW

Valid credit card numbers to test :

Visa : 4532069777249404 , 4916014173889326
Master : 5194775997768660, 5494872713298895
Amex : 340251740623507, 375921122764396
Discover : 6011489471829878 , 6011782582773435

Ref : https://en.wikipedia.org/wiki/Luhn_algorithm

LUHN Formula (Mod 10) for Validation of Primary Account Number

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 1 to each of the unaffected digits in the original number.

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.

Prefix, Length, and Check Digit Criteria

CARD TYPE Prefix Length Check digit algorithm
MASTERCARD 51-55 16 mod 10
VISA 4 13, 16 mod 10
AMEX 34

37
15 mod 10
Diners Club/
Carte Blanche
300-305
36
38
14 mod 10
Discover 6011 16 mod 10
enRoute 2014
2149
15 any
JCB 3 16 mod 10
JCB 2131
1800
15 mod 10

Leave a Reply

Your email address will not be published. Required fields are marked *