From d33d615a6249532d1d0691b515a63cc4127c61c9 Mon Sep 17 00:00:00 2001 From: rrbharath Date: Mon, 27 Jul 2026 17:40:53 -0400 Subject: [PATCH] feat(credit): rupay credit card validation --- README.md | 2 +- src/lib/isCreditCard.js | 1 + test/validators.test.js | 76 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f68954db3..70b81d530 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ Validator | Description **isBoolean(str [, options])** | check if the string is a boolean.
`options` is an object which defaults to `{ loose: false }`. If `loose` is set to false, the validator will strictly match ['true', 'false', '0', '1']. If `loose` is set to true, the validator will also match 'yes', 'no', and will match a valid boolean string of any case. (e.g.: ['true', 'True', 'TRUE']). **isBtcAddress(str)** | check if the string is a valid BTC address. **isByteLength(str [, options])** | check if the string's length (in UTF-8 bytes) falls in a range.

`options` is an object which defaults to `{ min: 0, max: undefined }`. -**isCreditCard(str [, options])** | check if the string is a credit card number.

`options` is an optional object that can be supplied with the following key(s): `provider` is an optional key whose value should be a string, and defines the company issuing the credit card. Valid values include `['amex', 'dinersclub', 'discover', 'jcb', 'mastercard', 'unionpay', 'visa']` or blank will check for any provider. +**isCreditCard(str [, options])** | check if the string is a credit card number.

`options` is an optional object that can be supplied with the following key(s): `provider` is an optional key whose value should be a string, and defines the company issuing the credit card. Valid values include `['amex', 'dinersclub', 'discover', 'jcb', 'mastercard', 'rupay', 'unionpay', 'visa']` or blank will check for any provider. **isCurrency(str [, options])** | check if the string is a valid currency amount.

`options` is an object which defaults to `{ symbol: '$', require_symbol: false, allow_space_after_symbol: false, symbol_after_digits: false, allow_negatives: true, parens_for_negatives: false, negative_sign_before_digits: false, negative_sign_after_digits: false, allow_negative_sign_placeholder: false, thousands_separator: ',', decimal_separator: '.', allow_decimal: true, require_decimal: false, digits_after_decimal: [2], allow_space_after_digits: false }`.
**Note:** The array `digits_after_decimal` is filled with the exact number of digits allowed not a range, for example a range 1 to 3 will be given as [1, 2, 3]. **isDataURI(str)** | check if the string is a [data uri format][Data URI Format]. **isDate(str [, options])** | check if the string is a valid date. e.g. [`2002-07-15`, new Date()].

`options` is an object which can contain the keys `format`, `strictMode` and/or `delimiters`.

`format` is a string and defaults to `YYYY/MM/DD`.

`strictMode` is a boolean and defaults to `false`. If `strictMode` is set to true, the validator will reject strings different from `format`.

`delimiters` is an array of allowed date delimiters and defaults to `['/', '-']`. diff --git a/src/lib/isCreditCard.js b/src/lib/isCreditCard.js index 938679d39..4120f86a8 100644 --- a/src/lib/isCreditCard.js +++ b/src/lib/isCreditCard.js @@ -7,6 +7,7 @@ const cards = { 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}$/; + rupay: /^(?:508[5-9][0-9]{12}|6069(?:8[5-9]|9[0-9])[0-9]{10}|607(?:[0-8][0-9]{2}|9(?:[0-7][0-9]|8[0-4]))[0-9]{10}|608(?:00[1-9]|0[1-9][0-9]|[1-4][0-9]{2}|500)[0-9]{10}|6521[5-9][0-9]{11}|652[2-9][0-9]{12}|6530[0-9]{12}|6531[0-4][0-9]{11}|817[2-9][0-9]{12}|81[89][0-9]{13}|820[01][0-9]{12})$/, 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 596c0b5c5..ef237f2d7 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -6418,6 +6418,17 @@ describe('Validators', () => { '4716989580001715211', '8171999927660000', '8171999900000000021', + '5085000000000007', + '6069850000000003', + '6070000000000002', + '6079840000000002', + '6080010000000009', + '6085000000000005', + '6521500000000006', + '6527658900001005', + '6531490000000008', + '8172000000000005', + '8201990000000002', ], invalid: [ 'foo', @@ -6432,6 +6443,10 @@ describe('Validators', () => { '623491788middle2863855', '6234917882863855suffix', '4716989580001715213', + '5084990000000000', + '6069840000000004', + '6085010000000004', + '8202000000000009', ], }); }); @@ -6484,6 +6499,7 @@ describe('Validators', () => { '6765780016990268', '8171999927660000', '8171999900000000021', + '5085000000000007', ], }); }); @@ -6520,6 +6536,7 @@ describe('Validators', () => { '6765780016990268', '8171999927660000', '8171999900000000021', + '5085000000000007', ], }); }); @@ -6557,6 +6574,7 @@ describe('Validators', () => { '6765780016990268', '8171999927660000', '8171999900000000021', + '5085000000000007', ], }); }); @@ -6594,6 +6612,7 @@ describe('Validators', () => { '6765780016990268', '8171999927660000', '8171999900000000021', + '5085000000000007', ], }); }); @@ -6630,6 +6649,61 @@ describe('Validators', () => { '6765780016990268', '8171999927660000', '8171999900000000021', + '5085000000000007', + ], + }); + }); + + + it('should validate RuPay provided credit cards', () => { + test({ + validator: 'isCreditCard', + args: [{ provider: 'RuPay' }], + valid: [ + '5085000000000007', + '6069850000000003', + '6070000000000002', + '6079840000000002', + '6080010000000009', + '6085000000000005', + '6521500000000006', + '6527658900001005', + '6531490000000008', + '8172000000000005', + '8201990000000002', + ], + invalid: [ + 'foo', + '2222155765072228', + '2225855203075256', + '2720428011723762', + '2718760626256570', + '36050234196908', + '375556917985515', + '375556917985515999999993', + '4716461583322103', + '4716-2210-5188-5662', + '4716989580001715211', + '4929 7226 5379 7141', + '5398228707871527', + '6234917882863855suffix', + '6283875070985593', + '6263892624162870', + '6234917882863855', + '6234698580215388', + '6226050967750613', + '6246281879460688', + '6283875070985593', + '6765780016990268', + '8171999927660000', + '8171999900000000021', + '5084990000000000', + '6069840000000004', + '6085010000000004', + '6521490000000000', + '6531500000000004', + '8171990000000008', + '8202000000000009', ], }); }); @@ -6665,6 +6739,7 @@ describe('Validators', () => { '4929 7226 5379 7141', '5398228707871527', '6234917882863855suffix', + '5085000000000007', ], }); }); @@ -6701,6 +6776,7 @@ describe('Validators', () => { '6765780016990268', '8171999927660000', '8171999900000000021', + '5085000000000007', ], }); });