note 29735 added to ref.pfpro
| From: | mitka at actdev dot com | Date: | Sun, 23 Feb 2003 16:45:41 +0000 |
| Subject: | note 29735 added to ref.pfpro | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44393@lists.php.net to get a copy of this message | ||
You might want to check the CC number for LUHN checksum before submitting the actual transaction.
function luhncheck($number) {
$l = strlen($number);
for ($i=0; $i<$l; $i++) {
$q = substr($number,$l-$i-1,1)*($i%2+1);
$r += ($q%10)+(int)($q/10);
}
return !($r%10);
}
returns true if card number is valid, $number is a string with digits only (no dashes or spaces).
Before LUHN check, you can verify the card no. prefix and the number length, here's what they
should be:
Visa: 4..., 16 digits
MC: 51-55..., 16 digits
Amex: 34... or 37..., 15 digits
Discover: 6011..., 16 digits.
Diners/CBlanche: 300-305..., 36..., 38..., 14 digits
JCB: 3..., 16 digits
JCB: 2131 or 1800, 15 digits
enRoute does not do LUHN verification.
See details at http://www.beachnet.com/~hstiles/cardtype.html
Dimitri Tarassenko
--
http://www.php.net/manual/en/ref.pfpro.php
http://master.php.net/manage/user-notes.php?action=edit+29735
http://master.php.net/manage/user-notes.php?action=delete+29735
http://master.php.net/manage/user-notes.php?action=reject+29735