Skip to content

Commit b72aabc

Browse files
authored
feat(isPostalCode): add PK locale (#2052)
* Add validation, tests for postal code locale PK Reference for valid list of postal codes: https://www.pakpost.gov.pk/postcodes.php * Fix: missing trailing comma results in failed tests * Move reference link for valid postal code list * Fix: missing comma in README.md
1 parent 991e5ac commit b72aabc

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Validator | Description
157157
**isOctal(str)** | check if the string is a valid octal number.
158158
**isPassportNumber(str, countryCode)** | check if the string is a valid passport number.<br/><br/>`countryCode` is one of `['AM', 'AR', 'AT', 'AU', 'AZ', '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', 'PH', 'PK', 'PL', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TH', 'TR', 'UA', 'US', 'ZA']`. Locale list is `validator.passportNumberLocales`.
159159
**isPort(str)** | check if the string is a valid port number.
160-
**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', 'CO', '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`.
160+
**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', 'CO', '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', 'PK', '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`.
161161
**isRFC3339(str)** | check if the string is a valid [RFC 3339][RFC 3339] date.
162162
**isRgbColor(str [,options])** | check if the string is a rgb or rgba color.<br/></br>`options` is an object with the following properties<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.<br/><br/>`allowSpaces` defaults to `true`, which prohibits whitespace. If set to false, whitespace between color values is allowed, such as `rgb(255, 255, 255)` or even `rgba(255, 128, 0, 0.7)`.
163163
**isSemVer(str)** | check if the string is a Semantic Versioning Specification (SemVer).

src/lib/isPostalCode.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ const patterns = {
5757
NO: fourDigit,
5858
NP: /^(10|21|22|32|33|34|44|45|56|57)\d{3}$|^(977)$/i,
5959
NZ: fourDigit,
60+
// https://www.pakpost.gov.pk/postcodes.php
61+
PK: fiveDigit,
6062
PL: /^\d{2}\-\d{3}$/,
6163
PR: /^00[679]\d{2}([ -]\d{4})?$/,
6264
PT: /^\d{4}\-\d{3}?$/,

test/validators.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12658,6 +12658,22 @@ describe('Validators', () => {
1265812658
'4144',
1265912659
],
1266012660
},
12661+
{
12662+
locale: 'PK',
12663+
valid: [
12664+
'25000',
12665+
'44000',
12666+
'54810',
12667+
'74200',
12668+
],
12669+
invalid: [
12670+
'5400',
12671+
'540000',
12672+
'NY540',
12673+
'540CA',
12674+
'540-0',
12675+
],
12676+
},
1266112677
{
1266212678
locale: 'MG',
1266312679
valid: [

0 commit comments

Comments
 (0)