From b3f2a228b54dc7a73446cdc9b64546ec74504d1a Mon Sep 17 00:00:00 2001 From: djeks922 Date: Fri, 7 Oct 2022 13:37:34 +0400 Subject: [PATCH 1/2] feat(isPassportNumber): add regex for Azerbaijan --- README.md | 2 +- src/lib/isPassportNumber.js | 3 ++- test/validators.js | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 961b50d9a..84e34f03b 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,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', 'fr-CA', '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', 'BY', 'BR', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IR', 'ID', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'MX', 'MY', 'MZ', 'NL', 'PL', 'PT', 'RO', 'RU', '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', 'AZ','BE', 'BG', 'BY', 'BR', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IR', 'ID', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'MX', 'MY', 'MZ', 'NL', 'PL', 'PT', 'RO', 'RU', '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', 'BA', 'BE', 'BG', 'BR', 'BY', 'CA', 'CH', 'CN', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HT', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'KR', 'LI', 'LK', 'LT', 'LU', 'LV', 'MG', 'MT', 'MX', 'MY', 'NL', 'NO', 'NP', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SG', 'SI', 'SK', 'TH', '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/src/lib/isPassportNumber.js b/src/lib/isPassportNumber.js index c434a7078..8c32fa6c0 100644 --- a/src/lib/isPassportNumber.js +++ b/src/lib/isPassportNumber.js @@ -10,7 +10,8 @@ const passportRegexByCountryCode = { AM: /^[A-Z]{2}\d{7}$/, // ARMENIA AR: /^[A-Z]{3}\d{6}$/, // ARGENTINA AT: /^[A-Z]\d{7}$/, // AUSTRIA - AU: /^[A-Z]\d{7}$/, // AUSTRALIA + AU: /^[A-Z]\d{7}$/, // AUSTRALIA, + AZ: /^[A-Z]{2,3}\d{7,8}$/, // AZERBAIJAN BE: /^[A-Z]{2}\d{6}$/, // BELGIUM BG: /^\d{9}$/, // BULGARIA BR: /^[A-Z]{2}\d{6}$/, // BRAZIL diff --git a/test/validators.js b/test/validators.js index 87f73ccd4..bdd187487 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2803,6 +2803,18 @@ describe('Validators', () => { ], }); + test({ + validator: 'isPassportNumber', + args: ['AZ'], + valid: [ + 'AZE16175905', + 'AA1617595', + ], + invalid: [ + 'A12345843', + ], + }); + test({ validator: 'isPassportNumber', args: ['BE'], From 21b45856cf7f450aaec73026f48b0c016425e708 Mon Sep 17 00:00:00 2001 From: djeks922 Date: Fri, 7 Oct 2022 13:39:54 +0400 Subject: [PATCH 2/2] fixing typo --- src/lib/isPassportNumber.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/isPassportNumber.js b/src/lib/isPassportNumber.js index 8c32fa6c0..92a5cec54 100644 --- a/src/lib/isPassportNumber.js +++ b/src/lib/isPassportNumber.js @@ -10,7 +10,7 @@ const passportRegexByCountryCode = { AM: /^[A-Z]{2}\d{7}$/, // ARMENIA AR: /^[A-Z]{3}\d{6}$/, // ARGENTINA AT: /^[A-Z]\d{7}$/, // AUSTRIA - AU: /^[A-Z]\d{7}$/, // AUSTRALIA, + AU: /^[A-Z]\d{7}$/, // AUSTRALIA AZ: /^[A-Z]{2,3}\d{7,8}$/, // AZERBAIJAN BE: /^[A-Z]{2}\d{6}$/, // BELGIUM BG: /^\d{9}$/, // BULGARIA