From 605b6060b31c834bb7931913a526e533de66a33d Mon Sep 17 00:00:00 2001 From: abhu85 <60182103+abhu85@users.noreply.github.com> Date: Mon, 2 Mar 2026 15:06:55 +0000 Subject: [PATCH] feat(isCreditCard): add Maestro and InstaPayment card support Add validation support for: - Maestro cards (prefixes 5018, 5020, 5038, 6304, 6759, 6761, 6763) - InstaPayment cards (prefixes 637, 638, 639) Both card types are added as individual providers with proper tests. Rescues stale PR #1701 (4.5 years old) by rebasing changes onto current code structure. The original PR used a single regex approach, but the codebase has since evolved to use individual provider regexes, so this implementation follows the current pattern. Original author: @avaly Co-Authored-By: Claude Opus 4.6 Co-Authored-By: avaly <3009556+avaly@users.noreply.github.com> --- src/lib/isCreditCard.js | 2 ++ test/validators.test.js | 45 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/lib/isCreditCard.js b/src/lib/isCreditCard.js index 938679d39..8024fcfff 100644 --- a/src/lib/isCreditCard.js +++ b/src/lib/isCreditCard.js @@ -5,7 +5,9 @@ const cards = { amex: /^3[47][0-9]{13}$/, dinersclub: /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/, discover: /^6(?:011|5[0-9][0-9])[0-9]{12,15}$/, + instapayment: /^63[7-9][0-9]{13}$/, jcb: /^(?:2131|1800|35\d{3})\d{11}$/, + maestro: /^(5018|5020|5038|6304|6759|6761|6763)[0-9]{8,15}$/, 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}$/; unionpay: /^(6[27][0-9]{14}|^(81[0-9]{14,17}))$/, visa: /^(?:4[0-9]{12})(?:[0-9]{3,6})?$/, diff --git a/test/validators.test.js b/test/validators.test.js index bcb3f0044..f60dd3660 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -6382,11 +6382,15 @@ describe('Validators', () => { '4716989580001715211', '8171999927660000', '8171999900000000021', + '5018000000000009', + '6370000000000009', ], invalid: [ 'foo', 'foo', '5398228707871528', + '637000000000000901', + '501800000000000901234567890', '2718760626256571', '2721465526338453', '2220175103860763', @@ -6670,6 +6674,47 @@ describe('Validators', () => { }); + it('should validate Maestro provided credit cards', () => { + test({ + validator: 'isCreditCard', + args: [{ provider: 'Maestro' }], + valid: [ + '5018000000000009', + '5020000000000005', + '5038000000000005', + '6304000000000000', + '6759000000000000', + ], + invalid: [ + 'foo', + '5019000000000000', + '4716461583322103', + '375556917985515', + ], + }); + }); + + + it('should validate InstaPayment provided credit cards', () => { + test({ + validator: 'isCreditCard', + args: [{ provider: 'InstaPayment' }], + valid: [ + '6370000000000009', + '6380000000000007', + '6390000000000005', + ], + invalid: [ + 'foo', + '6360000000000001', + '6400000000000002', + '4716461583322103', + '375556917985515', + ], + }); + }); + + it('should validate identity cards', () => { const fixtures = [ {