Skip to content

Commit f5bf121

Browse files
committed
fix(isCreditCard): fix Mastercard regex anchoring and digit length check
1 parent cfa6771 commit f5bf121

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/lib/isCreditCard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const cards = {
66
dinersclub: /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
77
discover: /^6(?:011|5[0-9][0-9])[0-9]{12,15}$/,
88
jcb: /^(?:2131|1800|35\d{3})\d{11}$/,
9-
mastercard: /^5[1-5][0-9]{2}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$/, // /^[25][1-7][0-9]{14}$/;
9+
mastercard: /^(?:5[1-5][0-9]{14}|(?:222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12})$/,
1010
unionpay: /^(6[27][0-9]{14}|^(81[0-9]{14,17}))$/,
1111
visa: /^(?:4[0-9]{12})(?:[0-9]{3,6})?$/,
1212
};

test/validators.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6598,6 +6598,11 @@ describe('Validators', () => {
65986598
'6765780016990268',
65996599
'8171999927660000',
66006600
'8171999900000000021',
6601+
'5108',
6602+
'foo2222155765072228',
6603+
'2222155765072228foo',
6604+
'51080000000000',
6605+
'51080000000000000',
66016606
],
66026607
});
66036608
});

0 commit comments

Comments
 (0)