Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Maestro credit card ranges #2223

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Validator | Description
**isBoolean(str [, options])** | check if the string is a boolean.<br/>`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.<br/><br/>`options` is an object which defaults to `{ min: 0, max: undefined }`.
**isCreditCard(str [, options])** | check if the string is a credit card number.<br/><br/> `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.<br/><br/> `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','maestro']` or blank will check for any provider.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • could you kindly correctly alphabetically sort the values?
  • nitpicking: could you get rid of the extra space at the end the of the line :-)

**isCurrency(str [, options])** | check if the string is a valid currency amount.<br/><br/>`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 }`.<br/>**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()].<br/><br/> `options` is an object which can contain the keys `format`, `strictMode` and/or `delimiters`.<br/><br/>`format` is a string and defaults to `YYYY/MM/DD`.<br/><br/>`strictMode` is a boolean and defaults to `false`. If `strictMode` is set to true, the validator will reject strings different from `format`.<br/><br/> `delimiters` is an array of allowed date delimiters and defaults to `['/', '-']`.
Expand Down
1 change: 1 addition & 0 deletions src/lib/isCreditCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}$/;
maestro: /^(493698|50(0[0-9]{3}|4(1[0-7][0-4]|7[6-9][0-9]))|50[678](7[789][0-9]|9[0-9]{2})|5[6-9]|63|67|6)\d{6,19}$/,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same nitpick as above: could you kindly correctly sort by alphabet, -> maestro should be before mastercard :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not 100% sure the regexp is 100% correct, e.g. this would return true for the following number:

6312345 - which has a length of 7 digits only

according to the source you provided the length is supposed to be
lengths: [12, 13, 14, 15, 16, 17, 18, 19]

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 @@ -5968,6 +5968,8 @@ describe('Validators', () => {
'4716989580001715211',
'8171999927660000',
'8171999900000000021',
'6759649826438453',
'6799990100000000019',
],
invalid: [
'foo',
Expand Down Expand Up @@ -6002,6 +6004,32 @@ describe('Validators', () => {
});
});

it('should validate Maestro provided credit cards', () => {
test({
validator: 'isCreditCard',
args: [{ provider: 'Maestro' }],
valid: [
'6759649826438453',
'6799990100000000019',
'6283875070985593',
],
invalid: [
'foo',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add some tests for too short numbers as well :-)

'2222155765072228',
'2225855203075256',
'2720428011723762',
'2718760626256570',
'36050234196908',
'375556917985515999999993',
'4716461583322103',
'4716-2210-5188-5662',
'4716989580001715211',
'4929 7226 5379 7141',
'5398228707871527',
'6234917882863855suffix',
],
});
});

it('should validate AmEx provided credit cards', () => {
test({
Expand Down
Loading