forked from ramoona/banks-db
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type.js
24 lines (23 loc) · 766 Bytes
/
type.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module.exports = function detectCardType(cardNumber) {
const card = cardNumber.toString().replace(/[^\d]/g, '');
const types = {
electron: /^(4026|417500|4405|4508|4844|4913|4917)\d+$/,
maestro: /^(5018|5020|5038|5612|5893|6304|6759|6761|6762|6763|0604|6390)\d+$/,
dankort: /^(5019)\d+$/,
interpayment: /^(636)\d+$/,
unionpay: /^(62|88)\d+$/,
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}$/,
discover: /^6(?:011|5[0-9]{2})[0-9]{12}$/,
jcb: /^(?:2131|1800|35\d{3})\d{11}$/,
forbrugsforeningen: /^(600)\d+$/
};
var type;
for (type in types) {
if (types[type].test(card)) {
return type.toString();
}
}
};