Hello,
If you want to get card type i.e. Visa, Master, Rupay etc. by card number, here is the code you can use.
This code uses regex for filtering out card type. You can use this function for getting the card type from card number (without space separation).
<?php
echo getCardType("512654265322155433");
function getCardType($cardNumber){
if($cardNumber[0] == 4){
return "VISA";
}
else if(mb_ereg("^508[5-9][0-9][0-9]|60698[5-9]|60699[0-9]|607[0-8][0-9][0-9]|6079[0-7][0-9]|60798[0-4]|(?!608000)608[0-4][0-9][0-9]|608500|6521[5-9][0-9]|652[2-9][0-9][0-9]|6530[0-9][0-9]|6531[0-4][0-9]",$cardNumber)){
return "RUPAY";
} else if (mb_ereg_match("^((6304)|(6706)|(6771)|(6709))[\\d]+",$cardNumber)) {
return "LASER";
} else if (mb_ereg("6(?:011|5[0-9]{2})[0-9]{12}[\\d]+",$cardNumber)) {
return "LASER";
} else if (mb_ereg_match("(5[06-8]|6\\d)\\d{14}(\\d{2,3})?[\\d]+",$cardNumber) ||mb_ereg_match("(5[06-8]|6\\d)[\\d]+",$cardNumber) || mb_ereg_match("((504([435|645|774|775|809|993]))|(60([0206]|[3845]))|(622[018])\\d)[\\d]+",$cardNumber)) {
if (strlen($cardNumber) >= 6) { // wel we have 6 digit bin
$substr = substr($cardNumber,0,6);
if (
strpos("504435",$substr)!==false ||
strpos("504645",$substr)!==false ||
strpos("504775",$substr)!==false ||
strpos("504809",$substr)!==false ||
strpos("504993",$substr)!==false ||
strpos("600206",$substr)!==false ||
strpos("603845",$substr)!==false ||
strpos("622018",$substr)!==false ||
strpos("504774",$substr)!==false
) {
return "SMAE";
}
}
return "MAES";
} else if (mb_ereg_match("^5[1-5][\\d]+",$cardNumber)) {
return "MAST";
} else if (mb_ereg_match("^3[47][\\d]+",$cardNumber)) {
return "AMEX";
} else if (($cardNumber[0]==3 && $cardNumber[1]==6) ||mb_ereg_match("^30[0-5][\\d]+",$cardNumber) ||mb_ereg_match("2(014|149)[\\d]+",$cardNumber)) {
return "DINR";
} else if (mb_ereg_match("^35(2[89]|[3-8][0-9])[\\d]+",$cardNumber)) {
return "JCB";
}
return "";
}
[Java]How to get credit card/debit card type(i.e. Visa, Master) from card number
No comments:
Post a Comment