Skip to content

Commit

Permalink
feat(isPostalCode): add SG & MY locales (#1502)
Browse files Browse the repository at this point in the history
Co-authored-by: Ho Chin Chee <[email protected]>
  • Loading branch information
stranger26 and Ho Chin Chee authored Nov 3, 2020
1 parent bab507a commit be8874d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,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.<br/><br/>(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'MT', '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,<br/><br/>(locale is one of `[ 'AD', 'AT', 'AU', 'AZ', 'BE', 'BG', 'BR', 'BY', 'CA', 'CH', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HT', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'NL', 'NO', 'NP', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', '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,<br/><br/>(locale is one of `[ 'AD', 'AT', 'AU', 'AZ', 'BE', 'BG', 'BR', 'BY', 'CA', 'CH', 'CZ', 'DE', 'DK', 'DO', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HT', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', '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`.).
**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.<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.
**isSemVer(str)** | check if the string is a Semantic Versioning Specification (SemVer).
Expand Down
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ var _isISO31661Alpha2 = _interopRequireDefault(require("./lib/isISO31661Alpha3")

var _isBase = _interopRequireDefault(require("./lib/isBase32"));

var _isBase2 = _interopRequireDefault(require("./lib/isBase64"));
var _isBase2 = _interopRequireDefault(require("./lib/isBase58"));

var _isBase3 = _interopRequireDefault(require("./lib/isBase64"));

var _isDataURI = _interopRequireDefault(require("./lib/isDataURI"));

Expand Down Expand Up @@ -267,7 +269,8 @@ var validator = {
isISO31661Alpha2: _isISO31661Alpha.default,
isISO31661Alpha3: _isISO31661Alpha2.default,
isBase32: _isBase.default,
isBase64: _isBase2.default,
isBase58: _isBase2.default,
isBase64: _isBase3.default,
isDataURI: _isDataURI.default,
isMagnetURI: _isMagnetURI.default,
isMimeType: _isMimeType.default,
Expand All @@ -290,4 +293,4 @@ var validator = {
var _default = validator;
exports.default = _default;
module.exports = exports.default;
module.exports.default = exports.default;
module.exports.default = exports.default;
2 changes: 2 additions & 0 deletions src/lib/isPostalCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const patterns = {
LV: /^LV\-\d{4}$/,
MX: fiveDigit,
MT: /^[A-Za-z]{3}\s{0,1}\d{4}$/,
MY: fiveDigit,
NL: /^\d{4}\s?[a-z]{2}$/i,
NO: fourDigit,
NP: /^(10|21|22|32|33|34|44|45|56|57)\d{3}$|^(977)$/i,
Expand All @@ -56,6 +57,7 @@ const patterns = {
RU: sixDigit,
SA: fiveDigit,
SE: /^[1-9]\d{2}\s?\d{2}$/,
SG: sixDigit,
SI: fourDigit,
SK: /^\d{3}\s?\d{2}$/,
TH: fiveDigit,
Expand Down
15 changes: 15 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -9002,6 +9002,14 @@ describe('Validators', () => {
'MSK8723',
],
},
{
locale: 'MY',
valid: [
'56000',
'12000',
'79502',
],
},
{
locale: 'PR',
valid: [
Expand Down Expand Up @@ -9062,6 +9070,13 @@ describe('Validators', () => {
'12140TH',
],
},
{
locale: 'SG',
valid: [
'308215',
'546080',
],
},
];

let allValid = [];
Expand Down
10 changes: 9 additions & 1 deletion validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2354,11 +2354,13 @@ var phones = {
'be-BY': /^(\+?375)?(24|25|29|33|44)\d{7}$/,
'bg-BG': /^(\+?359|0)?8[789]\d{7}$/,
'bn-BD': /^(\+?880|0)1[13456789][0-9]{8}$/,
'ca-AD': /^(\+376)?[346]\d{5}$/,
'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,
'de-DE': /^(\+49)?0?[1|3]([0|5][0-45-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/,
'de-AT': /^(\+43|0)\d{1,4}\d{3,12}$/,
'de-CH': /^(\+41|0)(7[5-9])\d{1,7}$/,
'de-LU': /^(\+352)?((6\d1)\d{6})$/,
'el-GR': /^(\+?30|0)?(69\d{8})$/,
'en-AU': /^(\+?61|0)4\d{8}$/,
'en-GB': /^(\+?44|0)7\d{9}$/,
Expand Down Expand Up @@ -2390,6 +2392,7 @@ var phones = {
'es-CL': /^(\+?56|0)[2-9]\d{1}\d{7}$/,
'es-CR': /^(\+506)?[2-8]\d{7}$/,
'es-DO': /^(\+?1)?8[024]9\d{7}$/,
'es-HN': /^(\+?504)?[9|8]\d{7}$/,
'es-EC': /^(\+?593|0)([2-7]|9[2-9])\d{7}$/,
'es-ES': /^(\+?34)?[6|7]\d{8}$/,
'es-PE': /^(\+?51)?9\d{8}$/,
Expand All @@ -2411,6 +2414,7 @@ var phones = {
'hu-HU': /^(\+?36)(20|30|70)\d{7}$/,
'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,
'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
'it-SM': /^((\+378)|(0549)|(\+390549)|(\+3780549))?6\d{5,9}$/,
'ja-JP': /^(\+81[ \-]?(\(0\))?|0)[6789]0[ \-]?\d{4}[ \-]?\d{4}$/,
'ka-GE': /^(\+?995)?(5|79)\d{7}$/,
'kk-KZ': /^(\+?7|8)?7\d{9}$/,
Expand All @@ -2424,12 +2428,13 @@ var phones = {
'nl-NL': /^(((\+|00)?31\(0\))|((\+|00)?31)|0)6{1}\d{8}$/,
'nn-NO': /^(\+?47)?[49]\d{7}$/,
'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,
'pt-BR': /(?=^(\+?5{2}\-?|0)[1-9]{2}\-?\d{4}\-?\d{4}$)(^(\+?5{2}\-?|0)[1-9]{2}\-?[6-9]{1}\d{3}\-?\d{4}$)|(^(\+?5{2}\-?|0)[1-9]{2}\-?9[6-9]{1}\d{3}\-?\d{4}$)/,
'pt-BR': /^((\+?55\ ?[1-9]{2}\ ?)|(\+?55\ ?\([1-9]{2}\)\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(9[2-9]{1}\d{3}\-?\d{4}))$/,
'pt-PT': /^(\+?351)?9[1236]\d{7}$/,
'ro-RO': /^(\+?4?0)\s?7\d{2}(\/|\s|\.|\-)?\d{3}(\s|\.|\-)?\d{3}$/,
'ru-RU': /^(\+?7|8)?9\d{9}$/,
'sl-SI': /^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/,
'sk-SK': /^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
'sq-AL': /^(\+355|0)6[789]\d{6}$/,
'sr-RS': /^(\+3816|06)[- \d]{5,9}$/,
'sv-SE': /^(\+?46|0)[\s\-]?7[\s\-]?[02369]([\s\-]?\d){7}$/,
'th-TH': /^(\+66|66|0)\d{9}$/,
Expand All @@ -2447,6 +2452,7 @@ phones['en-CA'] = phones['en-US'];
phones['fr-BE'] = phones['nl-BE'];
phones['zh-HK'] = phones['en-HK'];
phones['zh-MO'] = phones['en-MO'];
phones['ga-IE'] = phones['en-IE'];
function isMobilePhone(str, locale, options) {
assertString(str);

Expand Down Expand Up @@ -2825,6 +2831,7 @@ var patterns = {
LV: /^LV\-\d{4}$/,
MX: fiveDigit,
MT: /^[A-Za-z]{3}\s{0,1}\d{4}$/,
MY: fiveDigit,
NL: /^\d{4}\s?[a-z]{2}$/i,
NO: fourDigit,
NP: /^(10|21|22|32|33|34|44|45|56|57)\d{3}$|^(977)$/i,
Expand All @@ -2836,6 +2843,7 @@ var patterns = {
RU: sixDigit,
SA: fiveDigit,
SE: /^[1-9]\d{2}\s?\d{2}$/,
SG: sixDigit,
SI: fourDigit,
SK: /^\d{3}\s?\d{2}$/,
TH: fiveDigit,
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit be8874d

Please sign in to comment.