Skip to content

Commit

Permalink
feat(isPostalCode): added UA locale (#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim-Mazurok authored and chriso committed Dec 23, 2018
1 parent 285f58d commit 52f7673
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,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}`. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).
**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', 'BE', 'BG', 'CA', 'CH', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IL', 'IN', 'IS', 'IT', 'JP', 'KE', 'LI', 'LT', 'LU', 'LV', 'MX', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'SA', 'SE', 'SI', 'TN', 'TW', '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,<br/><br/>(locale is one of `[ 'AD', 'AT', 'AU', 'BE', 'BG', 'CA', 'CH', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IL', 'IN', 'IS', 'IT', 'JP', 'KE', 'LI', 'LT', 'LU', 'LV', 'MX', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'SA', 'SE', 'SI', '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`.).
**isSurrogatePair(str)** | check if the string contains any surrogate pairs chars.
**isURL(str [, options])** | check if the string is an URL.<br/><br/>`options` is an object which defaults to `{ protocols: ['http','https','ftp'], require_tld: true, require_protocol: false, require_host: true, require_valid_protocol: true, allow_underscores: false, host_whitelist: false, host_blacklist: false, allow_trailing_dot: false, allow_protocol_relative_urls: false, disallow_auth: false }`.
**isUUID(str [, version])** | check if the string is a UUID (version 3, 4 or 5).
Expand Down
1 change: 1 addition & 0 deletions lib/isPostalCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var patterns = {
SK: /^\d{3}\s?\d{2}$/,
TN: fourDigit,
TW: /^\d{3}(\d{2})?$/,
UA: fiveDigit,
US: /^\d{5}(-\d{4})?$/,
ZA: fourDigit,
ZM: fiveDigit
Expand Down
1 change: 1 addition & 0 deletions src/lib/isPostalCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const patterns = {
SK: /^\d{3}\s?\d{2}$/,
TN: fourDigit,
TW: /^\d{3}(\d{2})?$/,
UA: fiveDigit,
US: /^\d{5}(-\d{4})?$/,
ZA: fourDigit,
ZM: fiveDigit,
Expand Down
8 changes: 8 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -6102,6 +6102,14 @@ describe('Validators', () => {
'AD700',
],
},
{
locale: 'UA',
valid: [
'65000',
'65080',
'01000',
],
},
];

let allValid = [];
Expand Down
1 change: 1 addition & 0 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,7 @@ var patterns = {
SK: /^\d{3}\s?\d{2}$/,
TN: fourDigit,
TW: /^\d{3}(\d{2})?$/,
UA: fiveDigit,
US: /^\d{5}(-\d{4})?$/,
ZA: fourDigit,
ZM: fiveDigit
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit 52f7673

Please sign in to comment.