Skip to content

Commit 8604748

Browse files
profnandaaJuanFML
andauthored
feat(isPassportNumber): new locales JM,KZ,LI,NZ
chore: fix merge conflicts for #1555 Co-authored-by: Juan Medina <jfml_97@live.com>
1 parent 6dba289 commit 8604748

3 files changed

Lines changed: 64 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Validator | Description
153153
**isMultibyte(str)** | check if the string contains one or more multibyte chars.
154154
**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', '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']`.
155155
**isOctal(str)** | check if the string is a valid octal number.
156-
**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.<br/><br/>`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', 'TH', 'TR', 'UA', 'US']`.
156+
**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.<br/><br/>`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', 'JM', 'JP', 'KR', 'KZ', 'LI', 'LT', 'LU', 'LV', 'LY', 'MT', 'MX', 'MY', 'MZ', 'NL', 'NZ', 'PL', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TH', 'TR', 'UA', 'US']`.
157157
**isPort(str)** | check if the string is a valid port number.
158158
**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', '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`.
159159
**isRFC3339(str)** | check if the string is a valid [RFC 3339][RFC 3339] date.

src/lib/isPassportNumber.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ const passportRegexByCountryCode = {
3737
IR: /^[A-Z]\d{8}$/, // IRAN
3838
IS: /^(A)\d{7}$/, // ICELAND
3939
IT: /^[A-Z0-9]{2}\d{7}$/, // ITALY
40+
JM: /^[Aa]\d{7}$/, // JAMAICA
4041
JP: /^[A-Z]{2}\d{7}$/, // JAPAN
4142
KR: /^[MS]\d{8}$/, // SOUTH KOREA, REPUBLIC OF KOREA, [S=PS Passports, M=PM Passports]
43+
KZ: /^[a-zA-Z]\d{7}$/, // KAZAKHSTAN
44+
LI: /^[a-zA-Z]\d{5}$/, // LIECHTENSTEIN
4245
LT: /^[A-Z0-9]{8}$/, // LITHUANIA
4346
LU: /^[A-Z0-9]{8}$/, // LUXEMBURG
4447
LV: /^[A-Z0-9]{2}\d{7}$/, // LATVIA
@@ -48,12 +51,13 @@ const passportRegexByCountryCode = {
4851
MY: /^[AHK]\d{8}$/, // MALAYSIA
4952
MX: /^\d{10,11}$/, // MEXICO
5053
NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/, // NETHERLANDS
54+
NZ: /^([Ll]([Aa]|[Dd]|[Ff]|[Hh])|[Ee]([Aa]|[Pp])|[Nn])\d{6}$/, // NEW ZELAND
5155
PL: /^[A-Z]{2}\d{7}$/, // POLAND
5256
PT: /^[A-Z]\d{6}$/, // PORTUGAL
5357
RO: /^\d{8,9}$/, // ROMANIA
5458
RU: /^\d{9}$/, // RUSSIAN FEDERATION
5559
SE: /^\d{8}$/, // SWEDEN
56-
SL: /^(P)[A-Z]\d{7}$/, // SLOVANIA
60+
SL: /^(P)[A-Z]\d{7}$/, // SLOVENIA
5761
SK: /^[0-9A-Z]\d{7}$/, // SLOVAKIA
5862
TH: /^[A-Z]{1,2}\d{6,7}$/, // THAILAND
5963
TR: /^[A-Z]\d{8}$/, // TURKEY

test/validators.test.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,6 +3190,18 @@ describe('Validators', () => {
31903190
],
31913191
});
31923192

3193+
test({
3194+
validator: 'isPassportNumber',
3195+
args: ['JM'],
3196+
valid: [
3197+
'A0123456',
3198+
],
3199+
invalid: [
3200+
's0123456',
3201+
'a01234567',
3202+
],
3203+
});
3204+
31933205
test({
31943206
validator: 'isPassportNumber',
31953207
args: ['JP'],
@@ -3217,6 +3229,31 @@ describe('Validators', () => {
32173229
],
32183230
});
32193231

3232+
test({
3233+
validator: 'isPassportNumber',
3234+
args: ['KZ'],
3235+
valid: [
3236+
'A0123456',
3237+
'b0123456',
3238+
],
3239+
invalid: [
3240+
'01234567',
3241+
'bb0123456',
3242+
],
3243+
});
3244+
3245+
test({
3246+
validator: 'isPassportNumber',
3247+
args: ['LI'],
3248+
valid: [
3249+
'a01234',
3250+
'f01234',
3251+
],
3252+
invalid: [
3253+
'012345',
3254+
],
3255+
});
3256+
32203257
test({
32213258
validator: 'isPassportNumber',
32223259
args: ['LT'],
@@ -3332,6 +3369,27 @@ describe('Validators', () => {
33323369
],
33333370
});
33343371

3372+
test({
3373+
validator: 'isPassportNumber',
3374+
args: ['NZ'],
3375+
valid: [
3376+
'Lf012345',
3377+
'La012345',
3378+
'Ld012345',
3379+
'Lh012345',
3380+
'ea012345',
3381+
'ep012345',
3382+
'n012345',
3383+
],
3384+
invalid: [
3385+
'Lp012345',
3386+
'nd012345',
3387+
'ed012345',
3388+
'eh012345',
3389+
'ef012345',
3390+
],
3391+
});
3392+
33353393
test({
33363394
validator: 'isPassportNumber',
33373395
args: ['PL'],

0 commit comments

Comments
 (0)