Skip to content

Commit 8d58ecb

Browse files
tanvirrbrubiin
andauthored
feat(isPostalCode): add BD locale (#2551)
Co-authored-by: Rubin Bhandari <[email protected]>
1 parent d91af4b commit 8d58ecb

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
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', '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`.
160+
**isPostalCode(str, locale)** | check if the string is a postal code.<br/><br/>`locale` is one of `['AD', 'AT', 'AU', 'AZ', 'BA', 'BD', '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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const patterns = {
1212
AU: fourDigit,
1313
AZ: /^AZ\d{4}$/,
1414
BA: /^([7-8]\d{4}$)/,
15+
BD: /^([1-8][0-9]{3}|9[0-4][0-9]{2})$/,
1516
BE: fourDigit,
1617
BG: fourDigit,
1718
BR: /^\d{5}-?\d{3}$/,

test/validators.test.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12418,7 +12418,41 @@ describe('Validators', () => {
1241812418
'2017',
1241912419
'0800',
1242012420
],
12421-
}, {
12421+
},
12422+
{
12423+
locale: 'BD',
12424+
valid: [
12425+
'1000',
12426+
'1200',
12427+
'1300',
12428+
'1400',
12429+
'1500',
12430+
'2000',
12431+
'3000',
12432+
'4000',
12433+
'5000',
12434+
'6000',
12435+
'7000',
12436+
'8000',
12437+
'9000',
12438+
'9400',
12439+
'9499',
12440+
],
12441+
invalid: [
12442+
'0999',
12443+
'9500',
12444+
'10000',
12445+
'12345',
12446+
'123',
12447+
'123456',
12448+
'abcd',
12449+
'123a',
12450+
'a123',
12451+
'12 34',
12452+
'12-34',
12453+
],
12454+
},
12455+
{
1242212456
locale: 'BY',
1242312457
valid: [
1242412458
'225320',

0 commit comments

Comments
 (0)