Skip to content

Commit 319f88e

Browse files
feat(isMobilePhone): add fr-ML (Mali) and fr-TG (Togo) locales
Add mobile phone number validation for Mali (fr-ML) and Togo (fr-TG). Mali (+223): - Mobile operators: Orange (7x), Malitel (6x, 9x) - Pattern: /^(\+?223)?[679]\d{7}$/ - Based on ITU-T numbering plan for Mali Togo (+228): - Mobile operators: Togocel (70-73, 90-93), Moov (78-79, 96-99) - Excludes non-existent prefixes 74-77 and 94-95 - Pattern: /^(\+?228)?(7([0-3]|[89])|9([0-3]|[6-9]))\d{6}$/ - Based on ITU-T numbering plan for Togo Closes #1761
1 parent 9fa1e3a commit 319f88e

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ Validator | Description
150150
**isMailtoURI(str, [, options])** | check if the string is a [Mailto URI format][Mailto URI Format].<br/><br/>`options` is an object of validating emails inside the URI (check `isEmail`s options for details).
151151
**isMD5(str)** | check if the string is a MD5 hash.<br/><br/>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).
152152
**isMimeType(str)** | check if the string matches to a valid [MIME type][MIME Type] format.
153-
**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,<br/><br/>`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-DJ', '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', 'mk-MK', '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).<br/><br/>`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`.
153+
**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,<br/><br/>`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-DJ', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-ML', 'fr-MQ', 'fr-PF', 'fr-RE', 'fr-TG', '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', 'mk-MK', '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).<br/><br/>`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`.
154154
**isMongoId(str)** | check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid].
155155
**isMultibyte(str)** | check if the string contains one or more multibyte chars.
156156
**isNumeric(str [, options])** | check if the string contains only numbers.<br/><br/>`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 `.`).<br/><br/>`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']`.

src/lib/isMobilePhone.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ const phones = {
108108
'fr-GP': /^(\+?590|0|00590)[67]\d{8}$/,
109109
'fr-MQ': /^(\+?596|0|00596)[67]\d{8}$/,
110110
'fr-PF': /^(\+?689)?8[789]\d{6}$/,
111+
'fr-ML': /^(\+?223)?[679]\d{7}$/,
111112
'fr-RE': /^(\+?262|0|00262)[67]\d{8}$/,
113+
'fr-TG': /^(\+?228)?(7([0-3]|[89])|9([0-3]|[6-9]))\d{6}$/,
112114
'fr-WF': /^(\+681)?\d{6}$/,
113115
'he-IL': /^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/,
114116
'hu-HU': /^(\+?36|06)(20|30|31|50|70)\d{7}$/,

test/validators.test.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8847,6 +8847,29 @@ describe('Validators', () => {
88478847
'+59661245789',
88488848
],
88498849
},
8850+
{
8851+
locale: 'fr-ML',
8852+
valid: [
8853+
'+22360123456',
8854+
'+22370123456',
8855+
'+22390123456',
8856+
'60123456',
8857+
'70123456',
8858+
'90123456',
8859+
'22360123456',
8860+
'22370123456',
8861+
'22390123456',
8862+
],
8863+
invalid: [
8864+
'1234567',
8865+
'123456789',
8866+
'+2231234567',
8867+
'+22350123456',
8868+
'+22380123456',
8869+
'+223601234567',
8870+
'NotANumber',
8871+
],
8872+
},
88508873
{
88518874
locale: 'fr-RE',
88528875
valid: [
@@ -8872,6 +8895,41 @@ describe('Validators', () => {
88728895
'+26261245789',
88738896
],
88748897
},
8898+
{
8899+
locale: 'fr-TG',
8900+
valid: [
8901+
'+22870123456',
8902+
'+22871123456',
8903+
'+22872123456',
8904+
'+22873123456',
8905+
'+22878123456',
8906+
'+22879123456',
8907+
'+22890123456',
8908+
'+22891123456',
8909+
'+22892123456',
8910+
'+22893123456',
8911+
'+22896123456',
8912+
'+22897123456',
8913+
'+22898123456',
8914+
'+22899123456',
8915+
'70123456',
8916+
'90123456',
8917+
'96123456',
8918+
],
8919+
invalid: [
8920+
'+22874123456',
8921+
'+22875123456',
8922+
'+22876123456',
8923+
'+22877123456',
8924+
'+22894123456',
8925+
'+22895123456',
8926+
'1234567',
8927+
'123456789',
8928+
'+2287012345',
8929+
'+228701234567',
8930+
'NotANumber',
8931+
],
8932+
},
88758933
{
88768934
locale: 'fr-PF',
88778935
valid: [

0 commit comments

Comments
 (0)