diff --git a/README.md b/README.md index f11e548b6..268b3f4cd 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ Validator | Description **isLowercase(str)** | check if the string is lowercase. **isMACAddress(str)** | check if the string is a MAC address. **isMD5(str)** | check if the string is a MD5 hash. -**isMobilePhone(str, locale)** | check if the string is a mobile phone number,

(locale is one of `['ar-AE', 'ar-DZ','ar-EG', 'ar-JO', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-HK', 'en-IN', 'en-KE', 'en-NG', 'en-NZ', 'en-RW', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'es-ES', 'en-PK', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'it-IT', 'ja-JP', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', 'sr-RS', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']` OR 'any'. If 'any' is used, function will check if any of the locales match). +**isMobilePhone(str, locale)** | check if the string is a mobile phone number,

(locale is one of `['ar-AE', 'ar-DZ','ar-EG', 'ar-JO', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-HK', 'en-IN', 'en-KE', 'en-NG', 'en-NZ', 'en-RW', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-PK', 'es-ES', 'et-EE', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'it-IT', 'ja-JP', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', 'sr-RS', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']` OR 'any'. If 'any' is used, function will check if any of the locales match). **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)** | check if the string contains only numbers. diff --git a/lib/isMobilePhone.js b/lib/isMobilePhone.js index b6b7eb973..a102261e3 100644 --- a/lib/isMobilePhone.js +++ b/lib/isMobilePhone.js @@ -38,6 +38,7 @@ var phones = { 'en-ZA': /^(\+?27|0)\d{9}$/, 'en-ZM': /^(\+?26)?09[567]\d{7}$/, 'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/, + 'et-EE': /^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/, 'fa-IR': /^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/, 'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/, 'fo-FO': /^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/, @@ -91,4 +92,4 @@ function isMobilePhone(str, locale) { } throw new Error('Invalid locale \'' + locale + '\''); } -module.exports = exports['default']; \ No newline at end of file +module.exports = exports['default']; diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index a0768d958..59712bb6a 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -27,6 +27,7 @@ const phones = { 'en-ZA': /^(\+?27|0)\d{9}$/, 'en-ZM': /^(\+?26)?09[567]\d{7}$/, 'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/, + 'et-EE': /^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/, 'fa-IR': /^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/, 'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/, 'fo-FO': /^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/, diff --git a/test/validators.js b/test/validators.js index bde1c3b9f..7b19a564b 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3418,6 +3418,28 @@ describe('Validators', function () { '754789321', ], }, + { + locale: 'et-EE', + valid: [ + '+372 512 34 567', + '372 512 34 567', + '+37251234567', + '51234567', + '81234567', + '+372842345678', + ], + invalid: [ + '12345', + '', + 'NotANumber', + '+333 51234567', + '61234567', + '+51234567', + '+372 539 57 4', + '+372 900 1234', + '12345678', + ], + }, { locale: 'pl-PL', valid: [