Skip to content

Commit 2811404

Browse files
committed
fix(isMobilePhone): Add mobile phone validation locale for Moldova(ro-MD, ru-MD)
1 parent f055c11 commit 2811404

3 files changed

Lines changed: 77 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Validator | Description
146146
**isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme).
147147
**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).
148148
**isMimeType(str)** | check if the string matches to a valid [MIME type](https://en.wikipedia.org/wiki/Media_type) format
149-
**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-IQ', ar-JO', 'ar-KW', 'ar-PS', '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', 'dv-MV', 'el-GR', 'en-AU', 'en-BM', 'en-BW', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-GY', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-KI', '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-CU', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-SV', 'es-UY', 'es-VE', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-BF', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-PF', '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', 'my-MM', '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', 'tg-TJ', 'th-TH', 'tk-TM', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', 'zh-TW', 'dz-BT']` 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`.
149+
**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-IQ', ar-JO', 'ar-KW', 'ar-PS', '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', 'dv-MV', 'el-GR', 'en-AU', 'en-BM', 'en-BW', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-GY', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-KI', '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-CU', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-SV', 'es-UY', 'es-VE', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-BF', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-PF', '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', 'my-MM', 'mz-MZ', 'nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'pt-AO', 'ro-MD', 'ro-RO', 'ru-MD', 'ru-RU', 'si-LK', 'sl-SI', 'sk-SK', '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', 'dz-BT']` 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`.
150150
**isMongoId(str)** | check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid].
151151
**isMultibyte(str)** | check if the string contains one or more multibyte chars.
152152
**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` 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']`.

src/lib/isMobilePhone.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ const phones = {
115115
'pt-BR': /^((\+?55\ ?[1-9]{2}\ ?)|(\+?55\ ?\([1-9]{2}\)\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(9[2-9]{1}\d{3}\-?\d{4}))$/,
116116
'pt-PT': /^(\+?351)?9[1236]\d{7}$/,
117117
'pt-AO': /^(\+244)\d{9}$/,
118+
'ro-MD': /^(\+373)(\/|\s|\.|\-|\()?\d{2,3}(\/|\s|\.|\-|\))?\d{1,2}(\/|\s|\.|\-|)?\d{2}(\/|\s|\.|\-|\()?\d{2}?$/,
118119
'ro-RO': /^(\+?4?0)\s?7\d{2}(\/|\s|\.|\-)?\d{3}(\s|\.|\-)?\d{3}$/,
120+
'ru-MD': /^(\+373)(\/|\s|\.|\-|\()?\d{2,3}(\/|\s|\.|\-|\))?\d{1,2}(\/|\s|\.|\-|)?\d{2}(\/|\s|\.|\-|\()?\d{2}$/,
119121
'ru-RU': /^(\+?7|8)?9\d{9}$/,
120122
'si-LK': /^(?:0|94|\+94)?(7(0|1|2|4|5|6|7|8)( |-)?)\d{7}$/,
121123
'sl-SI': /^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/,

test/validators.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8078,6 +8078,43 @@ describe('Validators', () => {
80788078
'310212345678',
80798079
],
80808080
},
8081+
{
8082+
locale: 'ro-MD',
8083+
valid: [
8084+
'+373(22)56-03-50',
8085+
'+373(22)56-73-13',
8086+
'+373(22)51-70-29',
8087+
'+373(552)3-49-08',
8088+
'+373(22)55-50-07',
8089+
'+373(22)71-76-29',
8090+
'+373(22)34-11-54',
8091+
'+373(552)5-25-10',
8092+
'+37355242510',
8093+
'+373 123 4567',
8094+
'+373 552 34 11 56',
8095+
'+373-532-4-11-56',
8096+
'+373.532.3.27.56',
8097+
'+373/532/29/01/28',
8098+
],
8099+
invalid: [
8100+
'0899312361819001',
8101+
'0217123456',
8102+
'622178878890',
8103+
'6221 740123456',
8104+
'0341 8123456',
8105+
'0778 89800910',
8106+
'0741 123456',
8107+
'+123 456 7890',
8108+
'+37421740123456',
8109+
'+37540 123 456',
8110+
'',
8111+
'ASDFGJKLmZXJtZtesting123',
8112+
'123456',
8113+
'740123456',
8114+
'+65640123456',
8115+
'+37610123456',
8116+
],
8117+
},
80818118
{
80828119
locale: 'ro-RO',
80838120
valid: [
@@ -8106,6 +8143,43 @@ describe('Validators', () => {
81068143
'+40210123456',
81078144
],
81088145
},
8146+
{
8147+
locale: 'ru-MD',
8148+
valid: [
8149+
'+373(22)56-03-50',
8150+
'+373(22)56-73-13',
8151+
'+373(22)51-70-29',
8152+
'+373(552)3-49-08',
8153+
'+373(22)55-50-07',
8154+
'+373(22)71-76-29',
8155+
'+373(22)34-11-54',
8156+
'+373(552)5-25-10',
8157+
'+37355242510',
8158+
'+373 123 4567',
8159+
'+373 552 34 11 56',
8160+
'+373-532-4-11-56',
8161+
'+373.532.3.27.56',
8162+
'+373/532/29/01/28',
8163+
],
8164+
invalid: [
8165+
'0899312361819001',
8166+
'0217123456',
8167+
'622178878890',
8168+
'6221 740123456',
8169+
'0341 8123456',
8170+
'0778 89800910',
8171+
'0741 123456',
8172+
'+123 456 7890',
8173+
'+37421740123456',
8174+
'+37540 123 456',
8175+
'',
8176+
'ASDFGJKLmZXJtZtesting123',
8177+
'123456',
8178+
'740123456',
8179+
'+65640123456',
8180+
'+37610123456',
8181+
],
8182+
},
81098183
{
81108184
locale: 'id-ID',
81118185
valid: [

0 commit comments

Comments
 (0)