Closed DouglasHennrich closed 8 years ago
It's not something that Card.io provides in the result, but it can be done via RegEx or some other analysis of the card number, usually based on the first few digits:
There is a table here: https://en.wikipedia.org/wiki/Bank_card_number
Oh sad :( Thanks
/*
@ detectCardType
*/
function detectCardType(number) {
var re = {
visa: /^4[0-9]{12}(?:[0-9]{3})?$/,
mastercard: /^5[1-5][0-9]{14}$/,
amex: /^3[47][0-9]{13}$/,
diners: /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
hipercard: /^(606282\d{10}(\d{3})?)|(3841\d{15})$/,
elo: function(cardNum){
var eloBins = [
"50670","50671","50672","50673","50674","50675","50676","50900","50901","50902",
"50903","50904","50905","50906","50907","401178","401179","431274","438935","451416",
"457393","457631","457632","504175","506699","506770","506771","506772","506773","506774",
"506775","506776","506777","506778","509080","509081","509082","509083","627780","636297"
];
if (cardNum === null || cardNum.length != 16){
return false;
}
return ( eloBins.indexOf(cardNum.substring(0,6)) > -1 || eloBins.indexOf(cardNum.substring(0,5)) > -1 );
}
};
if (re.visa.test(number)) return 'Visa';
if (re.mastercard.test(number)) return 'Mastercard';
if (re.amex.test(number)) return 'AmericanExpress';
if (re.diners.test(number)) return 'Diners';
if (re.hipercard.test(number)) return 'Hiper';
if (re.elo(number)) return 'Elo';
return null;
}
I use the Flags I need to =)
Nice, thanks! Might be worth adding to the docs
There's a way to expose the creditcard flag ? like
Visa
,Master
...