From 98ed13967343388ef5f46311d879d2bad8785953 Mon Sep 17 00:00:00 2001 From: Tarvo R Date: Wed, 18 Oct 2017 15:50:05 +0300 Subject: [PATCH 1/6] Add Estonian locale (et-EE) to isMobilePhone validator The validator checks for: a) If the country code is +372 (+ and whole country code optional) b) Number starts with 5, 81, 82, 83 or 84 c) The number contains 7 to 8 numbers --- lib/isMobilePhone.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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']; From fdbd4738bde82da0df6b97373b158386943caf82 Mon Sep 17 00:00:00 2001 From: Tarvo R Date: Tue, 24 Oct 2017 12:27:12 +0300 Subject: [PATCH 2/6] Add tests for isMobilePhone validator's et-EE locale --- test/validators.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/validators.js b/test/validators.js index bde1c3b9f..fda6ef3c9 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 4567', + '+37251234567', + '51234567', + '81234567', + '+372842345678', + ], + invalid: [ + '12345', + '', + 'NotANumber', + '+333 51234567', + '61234567', + '+51234567', + '+372 539 57 4', + '+372 900 1234', + '12345678' + ], + }, { locale: 'pl-PL', valid: [ From c597992f9656f679aeacf48ee370c9ca4d210cbe Mon Sep 17 00:00:00 2001 From: Tarvo R Date: Tue, 24 Oct 2017 12:31:40 +0300 Subject: [PATCH 3/6] Update README: add 'et-EE' locale to isMobilePhone docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. From 84b2efe36e600c803967fb5f5c334ed743fecc04 Mon Sep 17 00:00:00 2001 From: Tarvo R Date: Tue, 24 Oct 2017 12:35:49 +0300 Subject: [PATCH 4/6] Fix isMobilePhone 'et-EE' locale test case typo --- test/validators.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index fda6ef3c9..89d6bab6d 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3422,7 +3422,7 @@ describe('Validators', function () { locale: 'et-EE', valid: [ '+372 512 34 567', - '372 512 34 4567', + '372 512 34 567', '+37251234567', '51234567', '81234567', From 80d08ec68e37c6020a628d342484e6244e28b435 Mon Sep 17 00:00:00 2001 From: Tarvo R Date: Tue, 24 Oct 2017 12:39:59 +0300 Subject: [PATCH 5/6] Add isMobilePhone 'et-EE' locale to src/lib as well --- src/lib/isMobilePhone.js | 1 + 1 file changed, 1 insertion(+) 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}$/, From 9e9bc8164a8aebe998d414dc6d0bd96c8ff51b74 Mon Sep 17 00:00:00 2001 From: Tarvo R Date: Tue, 24 Oct 2017 12:42:04 +0300 Subject: [PATCH 6/6] Add missing comma --- test/validators.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index 89d6bab6d..7b19a564b 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3437,7 +3437,7 @@ describe('Validators', function () { '+51234567', '+372 539 57 4', '+372 900 1234', - '12345678' + '12345678', ], }, {