////////////////////////////////////////////////////
// //
// 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;