From f398eeece3714cae5c223f92894bbfe462238cc1 Mon Sep 17 00:00:00 2001 From: Evgeniy Dainovich Date: Tue, 6 Oct 2020 16:14:51 +0300 Subject: [PATCH 1/2] add Belarus to isPassportNumber values --- README.md | 2 +- lib/isPassportNumber.js | 2 ++ test/validators.js | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dc494c8bd..b83e89ceb 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ Validator | Description **isMultibyte(str)** | check if the string contains one or more multibyte chars. **isNumeric(str [, options])** | check if the string contains only numbers.

`options` is an object which defaults to `{no_symbols: false}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`locale` determine the decimal separator and is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`. **isOctal(str)** | check if the string is a valid octal number. -**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'MT', 'NL', 'PO', 'PT', 'RO', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. +**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'MT', 'NL', 'PO', 'PT', 'RO', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. **isPort(str)** | check if the string is a valid port number. **isPostalCode(str, locale)** | check if the string is a postal code,

(locale is one of `[ 'AD', 'AT', 'AU', 'AZ', 'BE', 'BG', 'BR', 'BY', 'CA', 'CH', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HT', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'NL', 'NO', 'NP', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SI', 'TN', 'TW', 'UA', 'US', 'ZA', 'ZM' ]` OR 'any'. If 'any' is used, function will check if any of the locals match. Locale list is `validator.isPostalCodeLocales`.). **isRFC3339(str)** | check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date. diff --git a/lib/isPassportNumber.js b/lib/isPassportNumber.js index 77ea0ea47..b0e719a64 100644 --- a/lib/isPassportNumber.js +++ b/lib/isPassportNumber.js @@ -28,6 +28,8 @@ var passportRegexByCountryCode = { // BELGIUM BG: /^\d{9}$/, // BULGARIA + BY: /^[A-Z]{2}\d{7}$/, + // BELARUS CA: /^[A-Z]{2}\d{6}$/, // CANADA CH: /^[A-Z]\d{7}$/, diff --git a/test/validators.js b/test/validators.js index 853e1068c..82adfbe82 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2090,6 +2090,18 @@ describe('Validators', () => { ], }); + test({ + validator: 'isPassportNumber', + args: ['BY'], + valid: [ + 'MP3899901', + ], + invalid: [ + '345333454', + 'FG53334542', + ], + }); + test({ validator: 'isPassportNumber', args: ['CA'], From 1bfbfb19e3b011ae36e7ac7719f0e68281ae3ebe Mon Sep 17 00:00:00 2001 From: Evgeniy Dainovich Date: Tue, 6 Oct 2020 16:30:44 +0300 Subject: [PATCH 2/2] fix tests --- lib/isPassportNumber.js | 2 -- src/lib/isPassportNumber.js | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/isPassportNumber.js b/lib/isPassportNumber.js index b0e719a64..77ea0ea47 100644 --- a/lib/isPassportNumber.js +++ b/lib/isPassportNumber.js @@ -28,8 +28,6 @@ var passportRegexByCountryCode = { // BELGIUM BG: /^\d{9}$/, // BULGARIA - BY: /^[A-Z]{2}\d{7}$/, - // BELARUS CA: /^[A-Z]{2}\d{6}$/, // CANADA CH: /^[A-Z]\d{7}$/, diff --git a/src/lib/isPassportNumber.js b/src/lib/isPassportNumber.js index 99bf4a601..97cac98fb 100644 --- a/src/lib/isPassportNumber.js +++ b/src/lib/isPassportNumber.js @@ -13,6 +13,7 @@ const passportRegexByCountryCode = { AU: /^[A-Z]\d{7}$/, // AUSTRALIA BE: /^[A-Z]{2}\d{6}$/, // BELGIUM BG: /^\d{9}$/, // BULGARIA + BY: /^[A-Z]{2}\d{7}$/, // BELARUS CA: /^[A-Z]{2}\d{6}$/, // CANADA CH: /^[A-Z]\d{7}$/, // SWITZERLAND CN: /^[GE]\d{8}$/, // CHINA [G=Ordinary, E=Electronic] followed by 8-digits