From 4cb177c1f3cb2f159eea869dec05b8dbf4804d6a Mon Sep 17 00:00:00 2001 From: Megan Date: Sun, 10 Oct 2021 13:47:04 -0500 Subject: [PATCH 1/5] Added new condition for Botswana New regex for Botswana numbers Phone number information was found from the following sources: - https://www.howtocallabroad.com/botswana/ - https://countrycode.org/botswana --- src/lib/isMobilePhone.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 8b56b769f..9607edcc2 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -54,6 +54,7 @@ const phones = { 'en-ZA': /^(\+?27|0)\d{9}$/, 'en-ZM': /^(\+?26)?09[567]\d{7}$/, 'en-ZW': /^(\+263)[0-9]{9}$/, + 'en-BW': /^(\+?267)\d{7,9}$/, 'es-AR': /^\+?549(11|[2368]\d)\d{8}$/, 'es-BO': /^(\+?591)?(6|7)\d{7}$/, 'es-CO': /^(\+?57)?3(0(0|1|2|4|5)|1\d|2[0-4]|5(0|1))\d{7}$/, From 5bd62c433e0cc9a52cab380a1cf8477eb62c675f Mon Sep 17 00:00:00 2001 From: Megan Date: Sun, 10 Oct 2021 13:47:41 -0500 Subject: [PATCH 2/5] Updated README.md to include en-BW Included the new case for Botswana (en-BW) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ff1e00dc..11d3b84a8 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', 'en-BW', '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`. **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 bb6f0caa12fc73ac9f0339e0ba959abee1332381 Mon Sep 17 00:00:00 2001 From: Megan Date: Sun, 10 Oct 2021 13:59:31 -0500 Subject: [PATCH 3/5] Added test cases for isMobilePhone en-BW Added some test cases to check length for the phone number & area code pattern. --- test/validators.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/validators.js b/test/validators.js index 91794d521..b8fc8b4bc 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7835,6 +7835,25 @@ describe('Validators', () => { '23274560591 ', ], }, + { + locale: 'en-BW', + valid: [ + '+26754868990', + '+267543687909', + '+2670745605', + '26774560591', + '2670745605', + ], + invalid: [ + '0799375902', + '12345', + '+2670745605448', + '2670745605482', + '267074560', + '2670ab5608', + '+267074560', + ], + }, { locale: 'az-AZ', valid: [ From ff1e91eb8b68f0cba8b77b8c84d1ee9334b2453e Mon Sep 17 00:00:00 2001 From: Megan Dolan Date: Sat, 23 Oct 2021 14:02:56 -0500 Subject: [PATCH 4/5] Changed regex for BW Fixed the pattern for Botswana mobile phone numbers and edited the test cases. I followed the convention from Table 8 of the national numbering plan document and the mobile number pattern on the Wiki page. --- src/lib/isMobilePhone.js | 2 +- test/validators.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 9607edcc2..cb6613421 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -54,7 +54,7 @@ const phones = { 'en-ZA': /^(\+?27|0)\d{9}$/, 'en-ZM': /^(\+?26)?09[567]\d{7}$/, 'en-ZW': /^(\+263)[0-9]{9}$/, - 'en-BW': /^(\+?267)\d{7,9}$/, + 'en-BW': /^(\+?267)?(7[1-8]{1})\d{6}$/, 'es-AR': /^\+?549(11|[2368]\d)\d{8}$/, 'es-BO': /^(\+?591)?(6|7)\d{7}$/, 'es-CO': /^(\+?57)?3(0(0|1|2|4|5)|1\d|2[0-4]|5(0|1))\d{7}$/, diff --git a/test/validators.js b/test/validators.js index b8fc8b4bc..855540668 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7838,20 +7838,26 @@ describe('Validators', () => { { locale: 'en-BW', valid: [ - '+26754868990', - '+267543687909', - '+2670745605', + '+26772868545', + '+26776368790', + '+26774560512', '26774560591', - '2670745605', + '26771560512', + '74560512', + '76710284', ], invalid: [ '0799375902', '12345', '+2670745605448', '2670745605482', + '+26778685451', + '+26770685451', '267074560', '2670ab5608', '+267074560', + '70560512', + '78710284', ], }, { From b3ef463ed9684097edd395f0a32409c6e8b46448 Mon Sep 17 00:00:00 2001 From: Megan Dolan Date: Sat, 23 Oct 2021 14:06:16 -0500 Subject: [PATCH 5/5] Update validators.js Oops! Looks like the file didn't update with some of my modified test cases - my apologies! --- test/validators.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/validators.js b/test/validators.js index 855540668..c8b0320e7 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7842,7 +7842,7 @@ describe('Validators', () => { '+26776368790', '+26774560512', '26774560591', - '26771560512', + '26778560512', '74560512', '76710284', ], @@ -7851,13 +7851,13 @@ describe('Validators', () => { '12345', '+2670745605448', '2670745605482', - '+26778685451', + '+26779685451', '+26770685451', '267074560', '2670ab5608', '+267074560', '70560512', - '78710284', + '79710284', ], }, {