From 1e82c0d5e45e4ff47c87f794b42a9e0123bd4483 Mon Sep 17 00:00:00 2001 From: Nimantha Cooray <54179737+nimanthadilz@users.noreply.github.com> Date: Sat, 30 Oct 2021 12:04:02 +0530 Subject: [PATCH] feat(isPostalCode): add `LK` (Sri Lanka) locale (#1788) * Add `LK` locale to `isPostalCode` * Add tests for `LK` locale of `isPostalCode` * Update README.md --- README.md | 2 +- src/lib/isPostalCode.js | 1 + test/validators.js | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a45d90981..dc054e7c3 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ Validator | Description **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', 'MY', 'MZ', '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,

(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', 'KR', '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`.). +**isPostalCode(str, locale)** | check if the string is a postal code,

(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', 'KR', 'LI', 'LK', '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. **isRgbColor(str [, includePercentValues])** | check if the string is a rgb or rgba color.

`includePercentValues` defaults to `true`. If you don't want to allow to set `rgb` or `rgba` values with percents, like `rgb(5%,5%,5%)`, or `rgba(90%,90%,90%,.3)`, then set it to false. **isSemVer(str)** | check if the string is a Semantic Versioning Specification (SemVer). diff --git a/src/lib/isPostalCode.js b/src/lib/isPostalCode.js index 915c27f2b..7ef17abcf 100644 --- a/src/lib/isPostalCode.js +++ b/src/lib/isPostalCode.js @@ -46,6 +46,7 @@ const patterns = { LT: /^LT\-\d{5}$/, LU: fourDigit, LV: /^LV\-\d{4}$/, + LK: fiveDigit, MX: fiveDigit, MT: /^[A-Za-z]{3}\s{0,1}\d{4}$/, MY: fiveDigit, diff --git a/test/validators.js b/test/validators.js index d81331f33..01dc22eb3 100644 --- a/test/validators.js +++ b/test/validators.js @@ -10178,6 +10178,20 @@ describe('Validators', () => { 'ab1234', ], }, + { + locale: 'LK', + valid: [ + '11500', + '22200', + '10370', + '43000', + ], + invalid: [ + '1234', + '789389', + '982', + ], + }, ]; let allValid = [];