我發現這個簡單的函數返回的4種最常見的信用卡類型。jQuery的發現信用卡類型
作爲新的jQuery的,什麼樣的jQuery插件我可以使用,以顯示信用卡類型,在一個輸入字段信用卡號碼的用戶類型?
function creditCardTypeFromNumber(num) {
// first, sanitize the number by removing all non-digit characters.
num = num.replace(/[^\d]/g,'');
// now test the number against some regexes to figure out the card type.
if (num.match(/^5[1-5]\d{14}$/)) {
return 'MasterCard';
} else if (num.match(/^4\d{15}/) || num.match(/^4\d{12}/)) {
return 'Visa';
} else if (num.match(/^3[47]\d{13}/)) {
return 'AmEx';
} else if (num.match(/^6011\d{12}/)) {
return 'Discover';
}
return 'UNKNOWN';
}
謝謝!
'change()'不會被觸發,直到文本輸入失去焦點。當你輸入 – Hussein 2011-03-07 02:58:14
時,使用keyup()代替驗證,我知道它有點老了,但我一直在尋找像這樣的東西。只是想要注意,@丹尼爾A.懷特你需要額外的)在第2行結束;) – stinkysGTI 2014-11-14 18:32:37