Credit Card Number validation using Lunh Algorithm

Credit cards or Debit cards are validated by a formula known as “Lunh Algorithm”. It is also known as “Modulus 10” algorithm. It is created by Hens Peter Lunh ( A scientist in IBM).
It is also used to validate IMEI Numbers and National Provider Ind

entifier Number in US.
Lunh Algorithm verify numbers against its check digit (i.e. Last number of credit card). To validate credit card number, it must pass Lunh Algorithm.
Validate the Credit card using Lunh Alogrithm

  • Step1. Reverse the credit card number e.g.
    4211 6880 3434 4563 =3654 4343 0886 1124
  •  

  • Step 2. Double the every even position digit like.
    3 (12) 5 (8) 4 (6) 4 (6) 0 (16) 8 (12) 1 (2) 2 (8)
  • Step 3. Make two digit numbers in to a single by adding both digits like (10=1 0=1, 16=(1 6)=7)
    3 (12=1 2=3) 5 8 4 6 4 6 0 (16=6 1=7) 8 (12=2 1=3) 1 2 2 8
  • Step 4. Get the sum of all numbers and divide them by 10. if the modulus of sum casino online is 0 then credit card number is valid number else credit card number is not valid. e.g.
    3 (12=1 2) 5 8 4 6 4 6 0 (16=6 1) 8 (12=2 1) 1 2 2 8=70

    mod 70/10 = 0 so this credit card is valid.

Get check Digit of Credit card number

  • Step 1. Reverse the first 15 digits of credit card number e.g.
    4211 6880 3434 456 = 654 4343 0886 1124
  •  

  • Step 2. Double the every odd position digits. eg.
    (12) 5 (8) 4 (6) 4 (6) 0 (16) 8 (12) 1 (2) 2 (8)
  • Step 3. Make two digit numbers in to a single by adding both digits like (10=1 0=1, 16=(1 6)=7)
    (12=1 2=3) 5 8 4 6 4 6 0 (16=6 1=7) 8 (12=2 1=3) 1 2 2 8
  • Step 3. Get the sum of all number and add a digit to the result so that the result is exactly divisible by 10 e.g.
    (12=1 2) 5 8 4 6 4 6 0 (16=6 1) 8 (12=2 1) 1 2 2 8=67

In the above exmple we have the sum 67 so I add 3 to it to make it exactly divisible by 10.
so 70 is divisible by 10 and 70-67=3
So 3 is the check digit of this credit card.
Verification of Credit card number in javascript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function isCreditCard(CC)
 {
 if (CC.length > 19)
	 {
		alert("You have entered an invalid card");
		 return false;
	 }
 sum = 0; mul = 1; l = CC.length;
 for (i = 0; i < l; i ) {
 digit = CC.substring(l-i-1,l-i);
 tproduct = parseInt(digit ,10)*mul;
 if (tproduct >= 10)
 sum = (tproduct % 10) 1;
 else
 sum = tproduct;
 if (mul == 1)
		 {
			 mul ;
		 }
 else
		 {
 mul--;
		 }
 }
 
	 if ((sum % 10) == 0)
	 {
		alert("Congrats you enter valid card number");
		 return true;
	 }
 else
	 {
		alert("You have entered an invalid card");
		 return false;
	 }
 }
Comments
  1. Ryan Johnson
    • Tamber
  2. Pop
  3. Stan
  4. Lipsey
  5. Shiers
  6. Yusi
  7. Abrell
  8. Sharon
  9. Chang
  10. Tiede
  11. Pesta
  12. cheap roxy ugg boots
  13. ultimate bind ugg boots uk
  14. Roun
  15. Katrina
  16. Caiyi
  17. Pandora

Leave a Reply

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

*