Skip to content

Commit f73e3f2

Browse files
fix: for validatorjs#2403 get list of supported countries for passports (validatorjs#2404)
See validatorjs#2404 (comment) --------- Co-authored-by: Derek Parnell <[email protected]>
1 parent 6e2f084 commit f73e3f2

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Validator | Description
155155
**isMultibyte(str)** | check if the string contains one or more multibyte chars.
156156
**isNumeric(str [, options])** | check if the string contains only numbers.<br/><br/>`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 `.`).<br/><br/>`locale` determines 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', 'eo', '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']`.
157157
**isOctal(str)** | check if the string is a valid octal number.
158-
**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.<br/><br/>`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', 'JM', 'JP', 'KR', 'KZ', 'LI', 'LT', 'LU', 'LV', 'LY', 'MT', 'MX', 'MY', 'MZ', 'NL', 'NZ', 'PH', 'PK', 'PL', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TH', 'TR', 'UA', 'US', 'ZA']`.
158+
**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.<br/><br/>`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', 'JM', 'JP', 'KR', 'KZ', 'LI', 'LT', 'LU', 'LV', 'LY', 'MT', 'MX', 'MY', 'MZ', 'NL', 'NZ', 'PH', 'PK', 'PL', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TH', 'TR', 'UA', 'US', 'ZA']`. Locale list is `validator.passportNumberLocales`.
159159
**isPort(str)** | check if the string is a valid port number.
160160
**isPostalCode(str, locale)** | check if the string is a postal code.<br/><br/>`locale` is one of `['AD', 'AT', 'AU', 'AZ', 'BA', 'BE', 'BG', 'BR', 'BY', 'CA', 'CH', 'CN', 'CO', '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 locales match. Locale list is `validator.isPostalCodeLocales`.
161161
**isRFC3339(str)** | check if the string is a valid [RFC 3339][RFC 3339] date.

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import isAbaRouting from './lib/isAbaRouting';
2222
import isAlpha, { locales as isAlphaLocales } from './lib/isAlpha';
2323
import isAlphanumeric, { locales as isAlphanumericLocales } from './lib/isAlphanumeric';
2424
import isNumeric from './lib/isNumeric';
25-
import isPassportNumber from './lib/isPassportNumber';
25+
import isPassportNumber, { locales as passportNumberLocales } from './lib/isPassportNumber';
2626
import isPort from './lib/isPort';
2727
import isLowercase from './lib/isLowercase';
2828
import isUppercase from './lib/isUppercase';
@@ -155,6 +155,7 @@ const validator = {
155155
isAlphanumericLocales,
156156
isNumeric,
157157
isPassportNumber,
158+
passportNumberLocales,
158159
isPort,
159160
isLowercase,
160161
isUppercase,

src/lib/isPassportNumber.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ const passportRegexByCountryCode = {
6969
ZA: /^[TAMD]\d{8}$/, // SOUTH AFRICA
7070
};
7171

72+
export const locales = Object.keys(passportRegexByCountryCode);
73+
7274
/**
7375
* Check if str is a valid passport number
7476
* relative to provided ISO Country Code.

test/exports.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ import { locales as isAlphanumericLocales } from '../src/lib/isAlphanumeric';
66
import { locales as isMobilePhoneLocales } from '../src/lib/isMobilePhone';
77
import { locales as isFloatLocales } from '../src/lib/isFloat';
88
import { locales as ibanCountryCodes } from '../src/lib/isIBAN';
9+
import { locales as passportNumberLocales } from '../src/lib/isPassportNumber';
910

1011
describe('Exports', () => {
12+
it('should export isPassportNumbers\'s supported locales', () => {
13+
assert.ok(passportNumberLocales instanceof Array);
14+
assert.ok(validator.passportNumberLocales instanceof Array);
15+
});
16+
1117
it('should export validators', () => {
1218
assert.strictEqual(typeof validator.isEmail, 'function');
1319
assert.strictEqual(typeof validator.isAlpha, 'function');

0 commit comments

Comments
 (0)