showing results for - "card type through card number"
Juan Sebastián
21 Oct 2016
1function detectCardType(number) {
2    var re = {
3        electron: /^(4026|417500|4405|4508|4844|4913|4917)\d+$/,
4        maestro: /^(5018|5020|5038|5612|5893|6304|6759|6761|6762|6763|0604|6390)\d+$/,
5        dankort: /^(5019)\d+$/,
6        interpayment: /^(636)\d+$/,
7        unionpay: /^(62|88)\d+$/,
8        visa: /^4[0-9]{12}(?:[0-9]{3})?$/,
9        mastercard: /^5[1-5][0-9]{14}$/,
10        amex: /^3[47][0-9]{13}$/,
11        diners: /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
12        discover: /^6(?:011|5[0-9]{2})[0-9]{12}$/,
13        jcb: /^(?:2131|1800|35\d{3})\d{11}$/
14    }
15
16    for(var key in re) {
17        if(re[key].test(number)) {
18            return key
19        }
20    }
21}
similar questions
counting cards