From c51f92e1cbd3aedef57f4e3deaaaa4e1eacd06d4 Mon Sep 17 00:00:00 2001 From: Wisu Suntoyo Date: Wed, 10 Apr 2019 15:17:34 +0700 Subject: [PATCH 1/3] fix(readme): add 'id-ID' in the isMobilePhone list (#1001) * Indonesian mobile operators 2018 * add 'id-ID' to Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 261b5e57a..7bdbc8f6b 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ Validator | Description **isMACAddress(str)** | check if the string is a MAC address.

`options` is an object which defaults to `{no_colons: false}`. If `no_colons` is true, the validator will allow MAC addresses without the colons. **isMD5(str)** | check if the string is a MD5 hash. **isMimeType(str)** | check if the string matches to a valid [MIME type](https://en.wikipedia.org/wiki/Media_type) format -**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,

(locale is either an array of locales (e.g `['sk-SK', 'sr-RS']`) OR one of `['ar-AE', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'be-BY', 'bg-BG', 'bn-BD', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GH', 'en-HK', 'en-IE', 'en-IN', 'en-KE', 'en-MU', en-NG', 'en-NZ', 'en-RW', 'en-SG', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-PK', 'es-ES', 'es-MX', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'it-IT', 'ja-JP', 'kk-KZ', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'pt-BR', 'ro-RO', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']` OR defaults to 'any'. If 'any' or a falsey value is used, function will check if any of the locales match).

`options` is an optional object that can be supplied with the following keys: `strictMode`, if this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`. Locale list is `validator.isMobilePhoneLocales`. +**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,

(locale is either an array of locales (e.g `['sk-SK', 'sr-RS']`) OR one of `['ar-AE', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'be-BY', 'bg-BG', 'bn-BD', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GH', 'en-HK', 'en-IE', 'en-IN', 'en-KE', 'en-MU', en-NG', 'en-NZ', 'en-RW', 'en-SG', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-PK', 'es-ES', 'es-MX', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'kk-KZ', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'pt-BR', 'ro-RO', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']` OR defaults to 'any'. If 'any' or a falsey value is used, function will check if any of the locales match).

`options` is an optional object that can be supplied with the following keys: `strictMode`, if this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`. Locale list is `validator.isMobilePhoneLocales`. **isMongoId(str)** | check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid]. **isMultibyte(str)** | check if the string contains one or more multibyte chars. **isNumeric(str [, options])** | check if the string contains only numbers.

`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 `.`). From 2c68a31e1c5f7c428e8e6fe3a71df65894e520f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D9=90Amr=20Alaa?= <3amr.3laa@gmail.com> Date: Thu, 11 Apr 2019 10:19:33 +0200 Subject: [PATCH 2/3] feat(isMobilePhone): add support for ar-EG 015 (#1010) feat(isMobilePhone): add support for ar-EG 015 --- src/lib/isMobilePhone.js | 2 +- test/validators.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 1f5481fc7..2e4fe74d3 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -4,7 +4,7 @@ import assertString from './util/assertString'; const phones = { 'ar-AE': /^((\+?971)|0)?5[024568]\d{7}$/, 'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/, - 'ar-EG': /^((\+?20)|0)?1[012]\d{8}$/, + 'ar-EG': /^((\+?20)|0)?1[0125]\d{8}$/, 'ar-IQ': /^(\+?964|0)?7[0-9]\d{8}$/, 'ar-JO': /^(\+?962|0)?7[789]\d{7}$/, 'ar-KW': /^(\+?965)[569]\d{7}$/, diff --git a/test/validators.js b/test/validators.js index 61ffbe479..dabe88cb3 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3380,8 +3380,12 @@ describe('Validators', () => { '+201274652177', '+201280134679', '+201090124576', + '+201583728900', + '201599495596', '201090124576', '01090124576', + '01538920744', + '1593075993', '1090124576', ], invalid: [ From 251041b91794650c281b3de8c85cb29662016efa Mon Sep 17 00:00:00 2001 From: Robertus Sonny Prakoso Date: Mon, 15 Apr 2019 12:43:27 +0700 Subject: [PATCH 3/3] feat(isPostalCode): add Indonesia validation (#999) * add Indonesian (id-ID) postal code validation * update readme --- README.md | 2 +- src/lib/isPostalCode.js | 1 + test/validators.js | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7bdbc8f6b..1851c42dc 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,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.

`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,

(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`.). +**isPostalCode(str, locale)** | check if the string is a postal code,

(locale is one of `[ 'AD', 'AT', 'AU', 'BE', 'BG', 'CA', 'CH', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'ID', '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.

`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). diff --git a/src/lib/isPostalCode.js b/src/lib/isPostalCode.js index cf0f83822..1ac1c9353 100644 --- a/src/lib/isPostalCode.js +++ b/src/lib/isPostalCode.js @@ -26,6 +26,7 @@ const patterns = { GR: /^\d{3}\s?\d{2}$/, HR: /^([1-5]\d{4}$)/, HU: fourDigit, + ID: fiveDigit, IL: fiveDigit, IN: sixDigit, IS: threeDigit, diff --git a/test/validators.js b/test/validators.js index dabe88cb3..ebddb84bf 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6045,6 +6045,15 @@ describe('Validators', () => { '39940', ], }, + { + locale: 'ID', + valid: [ + '10210', + '40181', + '55161', + '60233', + ], + }, { locale: 'BG', valid: [