Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/isCreditCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const cards = {
dinersclub: /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
discover: /^6(?:011|5[0-9][0-9])[0-9]{12,15}$/,
jcb: /^(?:2131|1800|35\d{3})\d{11}$/,
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}$/;
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})$/,
unionpay: /^(6[27][0-9]{14}|^(81[0-9]{14,17}))$/,
visa: /^(?:4[0-9]{12})(?:[0-9]{3,6})?$/,
};
Expand Down
28 changes: 28 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6635,6 +6635,34 @@ describe('Validators', () => {
});


it('should reject short and partial Mastercard numbers (#2717)', () => {
// The Mastercard pattern's unanchored alternation (`^5[1-5][0-9]{2}|...`)
// used to match any 51-55 prefix regardless of length (#2717).
test({
validator: 'isCreditCard',
valid: [
'5105105105105100',
'5398228707871527',
],
invalid: [
'5108',
'5108 5108 5108 5108 5108',
],
});
test({
validator: 'isCreditCard',
args: [{ provider: 'mastercard' }],
valid: [
'5105105105105100',
],
invalid: [
'5108',
'5108 5108 5108 5108 5108',
],
});
});


it('should validate Union Pay provided credit cards', () => {
test({
validator: 'isCreditCard',
Expand Down
Loading