Skip to content

Commit bb0dba6

Browse files
stranger26tux-tn
andauthored
feat(isPassportNumber): add MY locale (#1574)
* [feat] Malaysian Passport validation * Delete validator.js * Delete validator.min.js Co-authored-by: Sarhan Aissi <tux-tn@users.noreply.github.com>
1 parent 7989e5b commit bb0dba6

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Validator | Description
143143
**isMultibyte(str)** | check if the string contains one or more multibyte chars.
144144
**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` 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']`.
145145
**isOctal(str)** | check if the string is a valid octal number.
146-
**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', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`.
146+
**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', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'LY', 'MT', 'MY', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`.
147147
**isPort(str)** | check if the string is a valid port number.
148148
**isPostalCode(str, locale)** | check if the string is a postal code,<br/><br/>(locale is one of `[ 'AD', 'AT', 'AU', 'AZ', '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', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'MY', 'NL', 'NO', 'NP', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SG', 'SI', '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`.).
149149
**isRFC3339(str)** | check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date.

src/lib/isPassportNumber.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const passportRegexByCountryCode = {
4242
LV: /^[A-Z0-9]{2}\d{7}$/, // LATVIA
4343
LY: /^[A-Z0-9]{8}$/, // LIBYA
4444
MT: /^\d{7}$/, // MALTA
45+
MY: /^[AHK]\d{8}$/, // MALAYSIA
4546
NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/, // NETHERLANDS
4647
PO: /^[A-Z]{2}\d{7}$/, // POLAND
4748
PT: /^[A-Z]\d{6}$/, // PORTUGAL

test/validators.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,6 +2670,20 @@ describe('Validators', () => {
26702670
],
26712671
});
26722672

2673+
test({
2674+
validator: 'isPassportNumber',
2675+
args: ['MY'],
2676+
valid: [
2677+
'A00000000',
2678+
'H12345678',
2679+
'K43143233',
2680+
],
2681+
invalid: [
2682+
'A1234567',
2683+
'C01234567',
2684+
],
2685+
});
2686+
26732687
test({
26742688
validator: 'isPassportNumber',
26752689
args: ['NL'],

0 commit comments

Comments
 (0)