From 68537354fc289779ce24adff4c220d89ad24cfae Mon Sep 17 00:00:00 2001 From: anonymousFPP Date: Wed, 25 Sep 2024 20:12:35 +0530 Subject: [PATCH 1/6] add mexico --- README.md | 2 +- src/lib/isMobilePhone.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c1cadb9f..247e03872 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ Validator | Description **isMailtoURI(str, [, options])** | check if the string is a [Mailto URI format][Mailto URI Format].

`options` is an object of validating emails inside the URI (check `isEmail`s options for details). **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][MIME 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-EH', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-PS', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'az-AZ', 'az-LB', 'az-LY', 'be-BY', 'bg-BG', 'bn-BD', 'bs-BA', 'ca-AD', 'cs-CZ', 'da-DK', 'de-AT', 'de-CH', 'de-DE', 'de-LU', 'dv-MV', 'dz-BT', 'el-CY', 'el-GR', 'en-AG', 'en-AI', 'en-AU', 'en-BM', 'en-BS', 'en-BW', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-GY', 'en-HK', 'en-IE', 'en-IN', 'en-JM', 'en-KE', 'en-KI', 'en-KN', 'en-LS', 'en-MO', 'en-MT', 'en-MU', 'en-MW', 'en-NG', 'en-NZ', 'en-PG', 'en-PH', 'en-PK', 'en-RW', 'en-SG', 'en-SL', 'en-SS', 'en-TZ', 'en-UG', 'en-US', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-EC', 'es-ES', 'es-GT','es-HN', 'es-MX', 'es-NI', 'es-PA', 'es-PE', 'es-PY', 'es-SV', 'es-UY', 'es-VE', 'et-EE', 'fa-AF', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-BF', 'fr-BJ', 'fr-CD', 'fr-CF', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-PF', 'fr-RE', 'fr-WF', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'ir-IR', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'ky-KG', 'lt-LT', 'mg-MG', 'mn-MN', 'ms-MY', 'my-MM', 'mz-MZ', 'nb-NO', 'ne-NP', 'nl-AW', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-AO', 'pt-BR', 'pt-PT', 'ro-Md', 'ro-RO', 'ru-RU', 'si-LK', 'sk-SK', 'sl-SI', 'so-SO', 'sq-AL', 'sr-RS', 'sv-SE', 'tg-TJ', 'th-TH', 'tk-TM', '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-EH', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-PS', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'az-AZ', 'az-LB', 'az-LY', 'be-BY', 'bg-BG', 'bn-BD', 'bs-BA', 'ca-AD', 'cs-CZ', 'da-DK', 'de-AT', 'de-CH', 'de-DE', 'de-LU', 'dv-MV', 'dz-BT', 'el-CY', 'el-GR', 'en-AG', 'en-AI', 'en-AU', 'en-BM', 'en-BS', 'en-BW', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-GY', 'en-HK', 'en-IE', 'en-IN', 'en-JM', 'en-KE', 'en-KI', 'en-KN', 'en-LS', 'en-MO', 'en-MT', 'en-MU', 'en-MW', 'en-NG', 'en-NZ', 'en-PG', 'en-PH', 'en-PK', 'en-RW', 'en-SG', 'en-SL', 'en-SS', 'en-TZ', 'en-UG', 'en-US', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-EC', 'es-ES', 'es-GT','es-HN', 'es-MX', 'es-NI', 'es-PA', 'es-PE', 'es-PY', 'es-SV', 'es-UY', 'es-VE', 'et-EE', 'fa-AF', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-BF', 'fr-BJ', 'fr-CD', 'fr-CF', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-PF', 'fr-RE', 'fr-WF', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'ir-IR', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'ky-KG', 'lt-LT', 'mg-MG', 'mn-MN', 'ms-MY', 'my-MM', 'mz-MZ', 'nb-NO', 'ne-NP', 'nl-AW', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-AO', 'pt-BR', 'pt-PT', 'ro-Md', 'ro-RO', 'ru-RU', 'si-LK', 'sk-SK', 'sl-SI', 'so-SO', 'sq-AL', 'sr-RS', 'sv-SE', 'tg-TJ', 'th-TH', 'tk-TM', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', 'zh-TW', 'en-MX']` 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` determines 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', 'eo', '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']`. diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index e5fb6bffd..b2042a874 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -160,6 +160,7 @@ const phones = { 'ar-YE': /^(((\+|00)9677|0?7)[0137]\d{7}|((\+|00)967|0)[1-7]\d{6})$/, 'ar-EH': /^(\+?212|0)[\s\-]?(5288|5289)[\s\-]?\d{5}$/, 'fa-AF': /^(\+93|0)?(2{1}[0-8]{1}|[3-5]{1}[0-4]{1})(\d{7})$/, + 'en-MX': /^(\+?52)?(1|01)?\d{10,11}$/, }; /* eslint-enable max-len */ From fbbee4008cdd2be650288cc28cd9f258dffe54ed Mon Sep 17 00:00:00 2001 From: anonymousFPP Date: Wed, 25 Sep 2024 22:42:36 +0530 Subject: [PATCH 2/6] add references and tests --- test/validators.test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/validators.test.js b/test/validators.test.js index 3b6ede69a..a8f114b5e 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -15399,5 +15399,22 @@ describe('Validators', () => { 'mailto:?subject=something&body=something else&cc=something@mail.com&bcc=hello@mail.com,another@mail.com&', ], }); + test({ + validator: 'isPhoneNumber', + args: ['en-MX'], + valid: [ + '+521234567890', + '+521987654321', + '1234567890', // valid without country code + '0987654321', + ], + invalid: [ + '123456789', // too short + '12345678901', // too long + '+531234567890', // wrong country code + '0234567890', // invalid leading digit + '+5212345678901', // too long with country code + ], + }); }); }); From ee842ab2718d13ee66d13d4fb97f7389fe51ffdd Mon Sep 17 00:00:00 2001 From: anonymousFPP Date: Thu, 26 Sep 2024 16:03:54 +0530 Subject: [PATCH 3/6] remove comment --- test/validators.test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/validators.test.js b/test/validators.test.js index a8f114b5e..8362f6d90 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -15405,15 +15405,15 @@ describe('Validators', () => { valid: [ '+521234567890', '+521987654321', - '1234567890', // valid without country code + '1234567890', '0987654321', ], invalid: [ - '123456789', // too short - '12345678901', // too long - '+531234567890', // wrong country code - '0234567890', // invalid leading digit - '+5212345678901', // too long with country code + '123456789', + '12345678901', + '+531234567890', + '0234567890', + '+5212345678901', ], }); }); From 23e2fda7c82d220fbefc4c70215b51ab56c1034f Mon Sep 17 00:00:00 2001 From: anonymousFPP Date: Thu, 26 Sep 2024 16:09:07 +0530 Subject: [PATCH 4/6] remove trailing space --- test/validators.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/validators.test.js b/test/validators.test.js index 8362f6d90..9c3366da8 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -15415,6 +15415,6 @@ describe('Validators', () => { '0234567890', '+5212345678901', ], - }); + }); }); -}); +}); \ No newline at end of file From 27dccad18c9e4ad14dd7f3d71ad1b84820d5efa8 Mon Sep 17 00:00:00 2001 From: anonymousFPP Date: Thu, 26 Sep 2024 16:11:20 +0530 Subject: [PATCH 5/6] add new line --- test/validators.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validators.test.js b/test/validators.test.js index 9c3366da8..cc62f79e4 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -15417,4 +15417,4 @@ describe('Validators', () => { ], }); }); -}); \ No newline at end of file +}); From 8f8e7d35bd873834a8174499847a898839768129 Mon Sep 17 00:00:00 2001 From: anonymousFPP Date: Thu, 26 Sep 2024 16:42:43 +0530 Subject: [PATCH 6/6] add reference and test --- test/validators.test.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/test/validators.test.js b/test/validators.test.js index cc62f79e4..eb15a8b64 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -7220,6 +7220,25 @@ describe('Validators', () => { '+37492123456', ], }, + { + locale: 'en-MX', + valid: [ + '+5215551234567', + '5551234567', + '+5219991234567', + '9991234567', + ], + invalid: [ + '12345678', + '+52155512345', + '12345678901234', + '+1234567890', + '55512345', + 'abcd1234567', + '', + ' ', + ], + }, { locale: 'ar-AE', valid: [ @@ -15399,22 +15418,5 @@ describe('Validators', () => { 'mailto:?subject=something&body=something else&cc=something@mail.com&bcc=hello@mail.com,another@mail.com&', ], }); - test({ - validator: 'isPhoneNumber', - args: ['en-MX'], - valid: [ - '+521234567890', - '+521987654321', - '1234567890', - '0987654321', - ], - invalid: [ - '123456789', - '12345678901', - '+531234567890', - '0234567890', - '+5212345678901', - ], - }); }); });