note 29735 deleted from ref.pfpro by danbrown

From: Date: Fri, 26 Sep 2008 15:20:35 +0000
Subject: note 29735 deleted from ref.pfpro by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-144778@lists.php.net to get a copy of this message
Note Submitter: mitka at actdev dot com ---- 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

« previous php.notes (#144778) next »