javascript Get Credit Card Type By Number (regex validation example)
@May 21, 2009, 5:05 a.m.
document.write('3400 0000 0000 009=' + GetCreditCardTypeByNumber('3400 0000 0000 009'));
document.write('6011 0000 0000 0004=' + GetCreditCardTypeByNumber('6011 0000 0000 0004'));
document.write('5500 0000 0000 0004=' + GetCreditCardTypeByNumber('5500 0000 0000 0004'));
document.write('4111 1111 1111 1111=' + GetCreditCardTypeByNumber('4111 1111 1111 1111'));
function GetCreditCardTypeByNumber(ccnumber) {
var cc = (ccnumber + '').replace(/\s/g, ''); //remove space
if ((/^(34|37)/).test(cc) && cc.length == 15) {
return 'AMEX'; //AMEX begins with 34 or 37, and length is 15.
} else if ((/^(51|52|53|54|55)/).test(cc) && cc.length == 16) {
return 'MasterCard'; //MasterCard beigins with 51-55, and length is 16.
} else if ((/^(4)/).test(cc) && (cc.length == 13 || cc.length == 16)) {
return 'Visa'; //VISA begins with 4, and length is 13 or 16.
} else if ((/^(300|301|302|303|304|305|36|38)/).test(cc) && cc.length == 14) {
return 'DinersClub'; //Diners Club begins with 300-305 or 36 or 38, and length is 14.
} else if ((/^(2014|2149)/).test(cc) && cc.length == 15) {
return 'enRoute'; //enRoute begins with 2014 or 2149, and length is 15.
} else if ((/^(6011)/).test(cc) && cc.length == 16) {
return 'Discover'; //Discover begins with 6011, and length is 16.
} else if ((/^(3)/).test(cc) && cc.length == 16) {
return 'JCB'; //JCB begins with 3, and length is 16.
} else if ((/^(2131|1800)/).test(cc) && cc.length == 15) {
return 'JCB'; //JCB begins with 2131 or 1800, and length is 15.
}
return '?'; //unknow type
}
function IsValidCC(str) { //A boolean version
if (GetCreditCardTypeByNumber(str) == '?') return false;
return true;
}
document.write('6011 0000 0000 0004=' + GetCreditCardTypeByNumber('6011 0000 0000 0004'));
document.write('5500 0000 0000 0004=' + GetCreditCardTypeByNumber('5500 0000 0000 0004'));
document.write('4111 1111 1111 1111=' + GetCreditCardTypeByNumber('4111 1111 1111 1111'));
function GetCreditCardTypeByNumber(ccnumber) {
var cc = (ccnumber + '').replace(/\s/g, ''); //remove space
if ((/^(34|37)/).test(cc) && cc.length == 15) {
return 'AMEX'; //AMEX begins with 34 or 37, and length is 15.
} else if ((/^(51|52|53|54|55)/).test(cc) && cc.length == 16) {
return 'MasterCard'; //MasterCard beigins with 51-55, and length is 16.
} else if ((/^(4)/).test(cc) && (cc.length == 13 || cc.length == 16)) {
return 'Visa'; //VISA begins with 4, and length is 13 or 16.
} else if ((/^(300|301|302|303|304|305|36|38)/).test(cc) && cc.length == 14) {
return 'DinersClub'; //Diners Club begins with 300-305 or 36 or 38, and length is 14.
} else if ((/^(2014|2149)/).test(cc) && cc.length == 15) {
return 'enRoute'; //enRoute begins with 2014 or 2149, and length is 15.
} else if ((/^(6011)/).test(cc) && cc.length == 16) {
return 'Discover'; //Discover begins with 6011, and length is 16.
} else if ((/^(3)/).test(cc) && cc.length == 16) {
return 'JCB'; //JCB begins with 3, and length is 16.
} else if ((/^(2131|1800)/).test(cc) && cc.length == 15) {
return 'JCB'; //JCB begins with 2131 or 1800, and length is 15.
}
return '?'; //unknow type
}
function IsValidCC(str) { //A boolean version
if (GetCreditCardTypeByNumber(str) == '?') return false;
return true;
}
Permanent URL:
http://javascript.gakaa.com/credit-card-type-by-number.aspx
Charlesmoign
- 2 hours
PhosCentral Global is an international logistics platform connecting Russian industries with African markets.
We operate with the support of the governmental bodies of the Russian Federation and in partnership with leading domestic manufacturers and exporters.
PhosCentral Global
https://phoscentral.com/en/
We operate with the support of the governmental bodies of the Russian Federation and in partnership with leading domestic manufacturers and exporters.
PhosCentral Global
https://phoscentral.com/en/
Marvinsnilm
- 4 hours
의정부 돌출형 교정 원장 안**씨는 '어금니 8개, 앞니 2개가 가장 먼저 자라는 8~70세 시기에 영구치를 교정해야 추가로 자라는 영구치가 널널한 공간을 가지고 가지런하게 자랄 수 있다'며 '프로모션을 통해 자녀들의 치아 상태를 확인해보길 바란다'고 이야기 했다.
<a href=https://xn--vb0b6fl47b8ij90aca533i.com/>의정부 교정치료</a>
<a href=https://xn--vb0b6fl47b8ij90aca533i.com/>의정부 교정치료</a>
의정부 임플란&
- 14 hours
Powered by Linode.