From 317770172be57080d89f1f631bfc2ad5cc1ddee7 Mon Sep 17 00:00:00 2001 From: Mariusz Kogut Date: Tue, 26 May 2020 17:21:55 +0200 Subject: [PATCH 1/3] feat(isMobilePhone): add support for de-CH --- src/lib/isMobilePhone.js | 1 + test/validators.js | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index a194ba26d..795088cc4 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -21,6 +21,7 @@ const phones = { 'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/, 'de-DE': /^(\+49)?0?1(5[0-25-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}$/, 'el-GR': /^(\+?30|0)?(69\d{8})$/, 'en-AU': /^(\+?61|0)4\d{8}$/, 'en-GB': /^(\+?44|0)7\d{9}$/, diff --git a/test/validators.js b/test/validators.js index db9bc3960..45bfd18bc 100755 --- a/test/validators.js +++ b/test/validators.js @@ -6435,6 +6435,10 @@ describe('Validators', () => { '+254728530234', '+299 12 34 56', '+94766660206', + '+41761112233', + '+41771112233', + '+41781112233', + '+41791112233', ], invalid: [ '254728530234', From 93db2931b7e3a02dbbbadd3f1a3a6146ac9c4791 Mon Sep 17 00:00:00 2001 From: Mariusz Kogut Date: Wed, 27 May 2020 08:22:57 +0200 Subject: [PATCH 2/3] Tweak readme + move tests in new group --- README.md | 2 +- test/validators.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f930719a8..e6dd4215c 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ Validator | Description **isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). **isMD5(str)** | check if the string is a MD5 hash.

Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). **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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'be-BY', 'bg-BG', 'bn-BD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'es-CL', 'es-CR', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', '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-MO', '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 `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'be-BY', 'bg-BG', 'bn-BD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'es-CL', 'es-CR', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', '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-MO', '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 `.`). diff --git a/test/validators.js b/test/validators.js index 45bfd18bc..68cc27299 100755 --- a/test/validators.js +++ b/test/validators.js @@ -6465,6 +6465,22 @@ describe('Validators', () => { }); }); + // de-CH + test({ + validator: 'isMobilePhone', + valid: [ + '+41751112233', + '+41761112233', + '+41771112233', + '+41781112233', + '+41791112233', + ], + invalid: [ + '+41441112233', + ], + args: [], + }); + it('should error on invalid locale', () => { test({ validator: 'isMobilePhone', From 6b2817fc5b3c1501a9a0b4ef9ff21fd3c4e5422e Mon Sep 17 00:00:00 2001 From: Mariusz Kogut Date: Wed, 27 May 2020 08:29:25 +0200 Subject: [PATCH 3/3] Clean strict mode tests --- test/validators.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/validators.js b/test/validators.js index 50a0a2b0c..ec7677f51 100755 --- a/test/validators.js +++ b/test/validators.js @@ -6449,10 +6449,6 @@ describe('Validators', () => { '+254728530234', '+299 12 34 56', '+94766660206', - '+41761112233', - '+41771112233', - '+41781112233', - '+41791112233', ], invalid: [ '254728530234',