From 1c8947185c6e598234604a550635781fd8fa2de9 Mon Sep 17 00:00:00 2001 From: Beckett Normington Date: Sun, 10 Oct 2021 19:20:07 -0400 Subject: [PATCH 01/10] Add Cameroon validation regex I have added a regex for validating Cameroonian mobile numbers which should work. I'm not super comfortable with regular expressions, so if I have screwed something up, please let me know. I have done some basic testing and it has functioned fine thus far. --- src/lib/isMobilePhone.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 8b56b769f..5534888fc 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -74,6 +74,7 @@ const phones = { 'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/, 'fj-FJ': /^(\+?679)?\s?\d{3}\s?\d{4}$/, 'fo-FO': /^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/, + 'fr-CM': /^((237) ?|(\+237) ?)([0-9] ?){9}$/, 'fr-FR': /^(\+?33|0)[67]\d{8}$/, 'fr-GF': /^(\+?594|0|00594)[67]\d{8}$/, 'fr-GP': /^(\+?590|0|00590)[67]\d{8}$/, From 11524400803cd844a831aaf780b371f5f30a1a94 Mon Sep 17 00:00:00 2001 From: Beckett Normington Date: Sun, 10 Oct 2021 19:30:00 -0400 Subject: [PATCH 02/10] Update README to include fr-CM in isMobilePhone --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ff1e00dc..68d97886c 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,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', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', '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-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'es-VE', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'si-LK' 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', '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', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', '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-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'es-VE', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-CM', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', ''mz-MZ', nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-RO', 'ru-RU', 'si-LK' 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', '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}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`locale` determine the decimal separator and is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'fr-CA', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`. From 822b2127fbff8b15244d86a01e2784162b8ef544 Mon Sep 17 00:00:00 2001 From: Beckett Normington Date: Sun, 10 Oct 2021 19:42:10 -0400 Subject: [PATCH 03/10] Add (very) basic testing for Cameroonian mobile number --- test/validators.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/validators.js b/test/validators.js index 91794d521..db7e39cca 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7340,6 +7340,19 @@ describe('Validators', () => { '088-320000', ], }, + { + locale: 'fr-CM', + valid: [ + '+237 677 93 61 41', + '237123456789', + '+2379981248429', + '237193029202' + ], + invalid: [ + 'NotANumber', + '+(703)-572-2920', + '+237 123 45 67 890' + ], { locale: 'ko-KR', valid: [ From 44ae45a1c917b4fc53e5e25d6e7fad2f7ecc42cb Mon Sep 17 00:00:00 2001 From: Beckett Normington Date: Sun, 10 Oct 2021 19:43:07 -0400 Subject: [PATCH 04/10] Fix missing brace (whoops!) --- test/validators.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/validators.js b/test/validators.js index db7e39cca..73e83f5f0 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7353,6 +7353,7 @@ describe('Validators', () => { '+(703)-572-2920', '+237 123 45 67 890' ], + }, { locale: 'ko-KR', valid: [ From e7d32ae5d46e58319a457ae7d61bdd269e0f79b9 Mon Sep 17 00:00:00 2001 From: Beckett Normington Date: Sun, 10 Oct 2021 19:48:04 -0400 Subject: [PATCH 05/10] Fix commas (I hope) --- test/validators.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/validators.js b/test/validators.js index 73e83f5f0..5f57a1e36 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7346,12 +7346,12 @@ describe('Validators', () => { '+237 677 93 61 41', '237123456789', '+2379981248429', - '237193029202' + '237193029202', ], invalid: [ 'NotANumber', '+(703)-572-2920', - '+237 123 45 67 890' + '+237 123 45 67 890', ], }, { From b01fa0878bba41ca50a7f46cba3edfb4580b591e Mon Sep 17 00:00:00 2001 From: Beckett Normington Date: Sun, 10 Oct 2021 19:51:13 -0400 Subject: [PATCH 06/10] Fix sloppy tests Fix my sloppy tests. I'm really tired and probably should not be working on this, but I accidentally added an extra digit while typing. --- test/validators.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index 5f57a1e36..9cbde64c7 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7345,13 +7345,14 @@ describe('Validators', () => { valid: [ '+237 677 93 61 41', '237123456789', - '+2379981248429', + '+237998124842', '237193029202', ], invalid: [ 'NotANumber', '+(703)-572-2920', '+237 123 45 67 890', + '+2379981248429', ], }, { From 86720d890d68d8d45dd8a62da5f4661236f4070d Mon Sep 17 00:00:00 2001 From: Beckett Normington Date: Mon, 18 Oct 2021 16:27:22 -0400 Subject: [PATCH 07/10] Update regex for correctness Add mobile prefix (6) to regex, remove space allowance, and optimize regex --- src/lib/isMobilePhone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 5534888fc..25d384e6c 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -74,7 +74,7 @@ const phones = { 'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/, 'fj-FJ': /^(\+?679)?\s?\d{3}\s?\d{4}$/, 'fo-FO': /^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/, - 'fr-CM': /^((237) ?|(\+237) ?)([0-9] ?){9}$/, + 'fr-CM': /^(\+?237) ?6[0-9]{8}$/, 'fr-FR': /^(\+?33|0)[67]\d{8}$/, 'fr-GF': /^(\+?594|0|00594)[67]\d{8}$/, 'fr-GP': /^(\+?590|0|00590)[67]\d{8}$/, From c62fe96323b092814ad033ace84fbf4e2a31c421 Mon Sep 17 00:00:00 2001 From: Beckett Normington Date: Mon, 18 Oct 2021 16:28:28 -0400 Subject: [PATCH 08/10] Update tests for correctness --- test/validators.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/validators.js b/test/validators.js index 9cbde64c7..043f91a24 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7343,15 +7343,15 @@ describe('Validators', () => { { locale: 'fr-CM', valid: [ - '+237 677 93 61 41', - '237123456789', - '+237998124842', - '237193029202', + '+237677936141', + '237623456789', + '+237698124842', + '237693029202', ], invalid: [ 'NotANumber', '+(703)-572-2920', - '+237 123 45 67 890', + '+237 623 45 67 890', '+2379981248429', ], }, From a0c6226a60c285d03349b6afac134de8377461d9 Mon Sep 17 00:00:00 2001 From: Beckett Normington Date: Tue, 19 Oct 2021 16:50:13 -0400 Subject: [PATCH 09/10] Remove invalid space Sorry! --- src/lib/isMobilePhone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 25d384e6c..e7cb3d1fc 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -74,7 +74,7 @@ const phones = { 'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/, 'fj-FJ': /^(\+?679)?\s?\d{3}\s?\d{4}$/, 'fo-FO': /^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/, - 'fr-CM': /^(\+?237) ?6[0-9]{8}$/, + 'fr-CM': /^(\+?237)6[0-9]{8}$/, 'fr-FR': /^(\+?33|0)[67]\d{8}$/, 'fr-GF': /^(\+?594|0|00594)[67]\d{8}$/, 'fr-GP': /^(\+?590|0|00590)[67]\d{8}$/, From 9926f9e208c2817d339173fc7e339ecda281fd38 Mon Sep 17 00:00:00 2001 From: Beckett Normington Date: Tue, 19 Oct 2021 16:55:12 -0400 Subject: [PATCH 10/10] Rerun failed tests (internal server error) --- test/validators.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index 043f91a24..7ab85fa25 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7352,7 +7352,7 @@ describe('Validators', () => { 'NotANumber', '+(703)-572-2920', '+237 623 45 67 890', - '+2379981248429', + '+2379981247429', ], }, {