Hello Reader's if you need to make validation of credit GivenCard using PHP then is blog will be helpful to you.
This is only making the validation on user side you should better use seconder validation on payment gate way also.
So the code liberay for this card validation will go like this:-
function ValidateionHere($GivenCCOnCard, $DoubleValidation = false){
$GivenCard = array(
"visa" => "(4\d{12}(?:\d{3})?)",
"amex" => "(3[47]\d{13})",
"jcb" => "(35[2-8][89]\d\d\d{10})",
"maestro" => "((?:5020|5038|6304|6579|6761)\d{12}(?:\d\d)?)",
"solo" => "((?:6334|6767)\d{12}(?:\d\d)?\d?)",
"mastercard" => "(5[1-5]\d{14})",
"switch" => "(?:(?:(?:4903|4905|4911|4936|6333|6759)\d{12})|(?:(?:564182|633110)\d{10})(\d\d)?\d?)",
);
$From = array("Visa", "American Express", "JCB", "Maestro", "Solo", "Mastercard", "Switch");
$matches = array();
$pattern = "#^(?:".implode("|", $GivenCard).")$#";
$YourCard = preg_match($pattern, str_replace(" ", "", $GivenCCOnCard), $matches);
if($DoubleValidation && $YourCard > 0){
$YourCard = (validatecard($GivenCCOnCard))?1:0;
}
return ($YourCard>0)?$From[sizeof($matches)-2]:false;
}
$GivenCard = array(
"981 4573 2548 9852",
);
foreach($GivenCard as $c){
$check = ValidateionHere($c, true);
if($check!==false)
echo $c." - ".$check;
else
echo "$c - Not a match";
echo "<br/>";
}
Output:-
981 4573 2548 9852 - Maestro
0 Comment(s)