Skip to content

Commit da6a52e

Browse files
nimanthadilzprofnandaa
authored andcommitted
feat(isPostalCode): add LK (Sri Lanka) locale (#1788)
* Add `LK` locale to `isPostalCode` * Add tests for `LK` locale of `isPostalCode` * Update README.md
1 parent dac5814 commit da6a52e

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Validator | Description
147147
**isOctal(str)** | check if the string is a valid octal number.
148148
**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', 'MY', 'MZ', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`.
149149
**isPort(str)** | check if the string is a valid port number.
150-
**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', '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`.).
150+
**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', '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`.).
151151
**isRFC3339(str)** | check if the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date.
152152
**isRgbColor(str [, includePercentValues])** | check if the string is a rgb or rgba color.<br/><br/>`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.
153153
**isSemVer(str)** | check if the string is a Semantic Versioning Specification (SemVer).

src/lib/isPostalCode.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const patterns = {
4646
LT: /^LT\-\d{5}$/,
4747
LU: fourDigit,
4848
LV: /^LV\-\d{4}$/,
49+
LK: fiveDigit,
4950
MX: fiveDigit,
5051
MT: /^[A-Za-z]{3}\s{0,1}\d{4}$/,
5152
MY: fiveDigit,

test/validators.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10178,6 +10178,20 @@ describe('Validators', () => {
1017810178
'ab1234',
1017910179
],
1018010180
},
10181+
{
10182+
locale: 'LK',
10183+
valid: [
10184+
'11500',
10185+
'22200',
10186+
'10370',
10187+
'43000',
10188+
],
10189+
invalid: [
10190+
'1234',
10191+
'789389',
10192+
'982',
10193+
],
10194+
},
1018110195
];
1018210196

1018310197
let allValid = [];

0 commit comments

Comments
 (0)