wysiwyg logo אלגוריתם לבדיקת כרטיסי אשראי Credit Card Number formats

Some of the well known credit card issuer:

issuer format length Validation
American Express 3xxx xxxxxxx xxxxx [4 6 5] 15 Luhn algorithm
Visa 4xxx xxxx xxxx xxxx [4 4 4 4] 16 Luhn algorithm
Mastercard 5xxx xxxx xxxx xxxx [4 4 4 4] 16 Luhn algorithm
discover 6xxx xxxx xxxx xxxx [4 4 4 4] 16 Luhn algorithm
Isracard ישראכרד xxxx xxxx [4 4] 8 Isracard algorithm
Diners Club 3xxx xxxxxx xxxx [4 6 4] 14 Luhn algorithm
מנפיק פורמט מבנה אורך בדיקה
 

Isracard american-express master-card visa
Checking 4563 9601 2200 1999
4 5 6 3 9 6 0 1 2 2 0 0 1 9 9 9
x2 x1 x2 x1 x2 x1 x2 x1 x2 x1 x2 x1 x2 x1 x2 x1
4x2 = 8 5 6x2 = 12 3 9x2 = 18 6 0x2 = 0 1 2x2 = 4 2 0x2 = 0 0 1x2 = 2 9 9x2 = 18 9
8 5 (12) 1+2 = 3 3 (18) 1+8 = 9 6 0 1 4 2 0 0 2 9 (18) 1+8 = 9 9
8 + 5 + 3 + 3 + 9 + 6 + 0 + 1 + 4 + 2 + 0 + 0 + 2 + 9 + 9 + 9 = 70
Now we mod the sum by 10, if the remian is Zero the nuber is valid
OK : 70 Mod 10 = 0

JavaScript Luhn Credit Card number Validation
<script>
	var cardValid=function(cardNo){    
    var sum = 0, iNum;
    for( var i in cardNo+='' ){
		iNum = parseInt(cardNo[i]);
		sum += i%2?iNum:iNum>4?iNum*2%10+1:iNum*2;
    }
    return !(sum%10);
  };
</script>


Asp vb script IsraCard Credit Card number Validation (8 or 9 digits)

<%
Function IsraCardCheck(strNumber)
	comp1 = "987654321"
	comp2 = strNumber
	srez = 0
	if len(comp2) < 9 then comp2 = "0" & comp2
	for i = 1 to 9 
		a = mid(comp1, i, 1)
		b = mid(comp2, i, 1)
		c = a * b
		srez = srez + c
	next
	
	if srez mod 11 = 0 then
		IsraCheck = true
	else
		IsraCheck = false
	end if
End Function 
%>






xnet 1998 - 2011