This little function helps validating a given credit card number is legit:
function ValidateCreditCardNumber($cc_num)
{
$pattern = "/^3[47]\d{13}$/";//American Express
if (preg_match($pattern,$cc_num))
{
return true;
}
$pattern = "/^([30|36|38]{2})([0-9]{12})$/";//Diner's Club
if (preg_match($pattern,$cc_num))
{
return true;
}
$pattern = "/^6011\d{12}$/";//Discover Card
if (preg_match($pattern,$cc_num))
{
return true;
}
$pattern = "/^5[12345]\d{14}$/";//Mastercard
if (preg_match($pattern,$cc_num))
{
return true;
}
$pattern = "/^4\d{12}(\d\d\d){0,1}$/";//Visa
if (preg_match($pattern,$cc_num))
{
return true;
}
$pattern = "/^30[012345]\d{11}$/";//Diners
if (preg_match($pattern,$cc_num))
{
return true;
}
$pattern = "/^3[68]\d{12}$/";//Diners #2
if (preg_match($pattern,$cc_num))
{
return true;
}
// Not valid
return false;
}
-By Parthiv Patel
function ValidateCreditCardNumber($cc_num)
{
$pattern = "/^3[47]\d{13}$/";//American Express
if (preg_match($pattern,$cc_num))
{
return true;
}
$pattern = "/^([30|36|38]{2})([0-9]{12})$/";//Diner's Club
if (preg_match($pattern,$cc_num))
{
return true;
}
$pattern = "/^6011\d{12}$/";//Discover Card
if (preg_match($pattern,$cc_num))
{
return true;
}
$pattern = "/^5[12345]\d{14}$/";//Mastercard
if (preg_match($pattern,$cc_num))
{
return true;
}
$pattern = "/^4\d{12}(\d\d\d){0,1}$/";//Visa
if (preg_match($pattern,$cc_num))
{
return true;
}
$pattern = "/^30[012345]\d{11}$/";//Diners
if (preg_match($pattern,$cc_num))
{
return true;
}
$pattern = "/^3[68]\d{12}$/";//Diners #2
if (preg_match($pattern,$cc_num))
{
return true;
}
// Not valid
return false;
}
-By Parthiv Patel
Parthiv Patel
Bhaishri Info Solution
Sr. PHP Developer
Limdi Chowk, AT PO. Nar, Di. Anand
Nar, Gujarat
388150
India
pparthiv2412@gmail.com
7383343029
DOB: 12/24/1986
No comments:
Post a Comment