//////////////////////////////////////////////////// // // // credit card validation routine // // may 15, 2000 // // by ariso // // validatecardcode($number[,$cardtype]) // //////////////////////////////////////////////////// function validatecardcode($cardnumber, $cardtype = unknown) { //clean up input $cardtype = strtolower($cardtype); $cardnumber = ereg_replace( [-[:space:]], ,$cardnumber); //do type specific checks if ($cardtype == unknown) { //skip type specific checks } elseif ($cardtype == mastercard){ if (strlen($cardnumber) != 16 || !ereg( 5[1-5], $cardnumber)) return 0; } elseif ($cardtype == visa){ if ((strlen($cardnumber) != 13 && strlen($cardnumber) != 16) || substr($cardnumber, 0, 1) != 4) return 0; } elseif ($cardtype == amex){ if (strlen($cardnumber) != 15 || !ereg( 3[47], $cardnumber)) return a; } elseif ($cardtype == discover){ if (strlen($cardnumber) != 16 || substr($cardnumber, 0, 4) != 6011) return 0; } else { //invalid type entered return -1; } // start mod 10 checks $dig = tochararray($cardnumber); $numdig = sizeof ($dig); $intintj = 0; for ($inti=($numdig-2); $inti>=0; $inti-=2){ $dbl[$intintj] = $dig[$inti] * 2; $intintj++; } $dblsz = sizeof($dbl); $validate =0; for ($inti=0;$inti