Repository: validatorjs/validator.js
Pull request #1574 (2021-01-06 15:40:34)

Added Malaysian Passport validation
<!--
Add a descriptive title textbox above, e.g.
feat(validatorName): brief title of what has been done
-->

Added Malaysian Passport validation

Republish of #1501

## Checklist

- [x] PR contains only changes related; no stray files, etc.
- [x] README updated (where applicable)
- [x] Tests written (where applicable)


codecov[bot]: # [Codecov](https://codecov.io/gh/validatorjs/validator.js/pull/1574?src=pr&el=h1) Report
> Merging [#1574](https://codecov.io/gh/validatorjs/validator.js/pull/1574?src=pr&el=desc) (aeaec52) into [master](https://codecov.io/gh/validatorjs/validator.js/commit/bab507ad4a33156ece15582268b2fe0ab3bbca1d?el=desc) (bab507a) will **increase** coverage by `0.07%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/validatorjs/validator.js/pull/1574/graphs/tree.svg?width=650&height=150&src=pr&token=YzR3kbN1m2)](https://codecov.io/gh/validatorjs/validator.js/pull/1574?src=pr&el=tree)

```diff
@@             Coverage Diff             @@
##           master     #1574      +/-   ##
===========================================
+ Coverage   99.92%   100.00%   +0.07%     
===========================================
  Files          96       100       +4     
  Lines        1277      1793     +516     
===========================================
+ Hits         1276      1793     +517     
+ Misses          1         0       -1     
```


| [Impacted Files](https://codecov.io/gh/validatorjs/validator.js/pull/1574?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/lib/isPassportNumber.js](https://codecov.io/gh/validatorjs/validator.js/pull/1574/diff?src=pr&el=tree#diff-c3JjL2xpYi9pc1Bhc3Nwb3J0TnVtYmVyLmpz) | `100.00% <ø> (ø)` | |
| [src/index.js](https://codecov.io/gh/validatorjs/validator.js/pull/1574/diff?src=pr&el=tree#diff-c3JjL2luZGV4Lmpz) | `100.00% <0.00%> (ø)` | |
| [src/lib/alpha.js](https://codecov.io/gh/validatorjs/validator.js/pull/1574/diff?src=pr&el=tree#diff-c3JjL2xpYi9hbHBoYS5qcw==) | `100.00% <0.00%> (ø)` | |
| [src/lib/isFQDN.js](https://codecov.io/gh/validatorjs/validator.js/pull/1574/diff?src=pr&el=tree#diff-c3JjL2xpYi9pc0ZRRE4uanM=) | `100.00% <0.00%> (ø)` | |
| [src/lib/isAlpha.js](https://codecov.io/gh/validatorjs/validator.js/pull/1574/diff?src=pr&el=tree#diff-c3JjL2xpYi9pc0FscGhhLmpz) | `100.00% <0.00%> (ø)` | |
| [src/lib/isEmail.js](https://codecov.io/gh/validatorjs/validator.js/pull/1574/diff?src=pr&el=tree#diff-c3JjL2xpYi9pc0VtYWlsLmpz) | `100.00% <0.00%> (ø)` | |
| [src/lib/isDataURI.js](https://codecov.io/gh/validatorjs/validator.js/pull/1574/diff?src=pr&el=tree#diff-c3JjL2xpYi9pc0RhdGFVUkkuanM=) | `100.00% <0.00%> (ø)` | |
| [src/lib/isISO8601.js](https://codecov.io/gh/validatorjs/validator.js/pull/1574/diff?src=pr&el=tree#diff-c3JjL2xpYi9pc0lTTzg2MDEuanM=) | `100.00% <0.00%> (ø)` | |
| [src/lib/isBtcAddress.js](https://codecov.io/gh/validatorjs/validator.js/pull/1574/diff?src=pr&el=tree#diff-c3JjL2xpYi9pc0J0Y0FkZHJlc3MuanM=) | `100.00% <0.00%> (ø)` | |
| [src/lib/isMACAddress.js](https://codecov.io/gh/validatorjs/validator.js/pull/1574/diff?src=pr&el=tree#diff-c3JjL2xpYi9pc01BQ0FkZHJlc3MuanM=) | `100.00% <0.00%> (ø)` | |
| ... and [8 more](https://codecov.io/gh/validatorjs/validator.js/pull/1574/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/validatorjs/validator.js/pull/1574?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/validatorjs/validator.js/pull/1574?src=pr&el=footer). Last update [bab507a...aeaec52](https://codecov.io/gh/validatorjs/validator.js/pull/1574?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

profnandaa: @stranger26 -- please fix the merge conflicts on README and we should be good to go.
profnandaa: That was fast, thanks!

Patch:
diff --git a/README.md b/README.md
index de3089d..3354576 100644
--- a/README.md
+++ b/README.md
@@ -143,7 +143,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.<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']`.
 **isOctal(str)**                        | check if the string is a valid octal number.
-**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' ]`.
+**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' ]`.
 **isPort(str)**                         | check if the string is a valid port number.
 **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`.).
 **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 0c1582e..3572abd 100644
--- a/src/lib/isPassportNumber.js
+++ b/src/lib/isPassportNumber.js
@@ -42,6 +42,7 @@ const passportRegexByCountryCode = {
   LV: /^[A-Z0-9]{2}\d{7}$/, // LATVIA
   LY: /^[A-Z0-9]{8}$/, // LIBYA
   MT: /^\d{7}$/, // MALTA
+  MY: /^[AHK]\d{8}$/, // MALAYSIA
   NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/, // NETHERLANDS
   PO: /^[A-Z]{2}\d{7}$/, // POLAND
   PT: /^[A-Z]\d{6}$/, // PORTUGAL


Test patch:
diff --git a/test/validators.js b/test/validators.js
index d7550b3..4a4180a 100644
--- a/test/validators.js
+++ b/test/validators.js
@@ -2670,6 +2670,20 @@ describe('Validators', () => {
       ],
     });
 
+    test({
+      validator: 'isPassportNumber',
+      args: ['MY'],
+      valid: [
+        'A00000000',
+        'H12345678',
+        'K43143233',
+      ],
+      invalid: [
+        'A1234567',
+        'C01234567',
+      ],
+    });
+
     test({
       validator: 'isPassportNumber',
       args: ['NL'],