From ad06fc293c5d4573e4a061feafcf23779ca87fab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20=C5=BDilinskas?= Date: Tue, 6 Jun 2017 18:50:57 +0300 Subject: [PATCH 1/2] Added Lithuanian mobile phone pattern. --- lib/isMobilePhone.js | 3 ++- src/lib/isMobilePhone.js | 1 + test/validators.js | 18 ++++++++++++++++++ validator.js | 3 ++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/isMobilePhone.js b/lib/isMobilePhone.js index 438270d0c..ea3f9b63c 100644 --- a/lib/isMobilePhone.js +++ b/lib/isMobilePhone.js @@ -34,6 +34,7 @@ var phones = { 'fr-FR': /^(\+?33|0)[67]\d{8}$/, 'he-IL': /^(\+972|0)([23489]|5[0248]|77)[1-9]\d{6}/, 'hu-HU': /^(\+?36)(20|30|70)\d{7}$/, + 'lt-LT': /^(\+370|8)\d{8}$/, 'id-ID': /^(\+?62|0[1-9])[\s|\d]+$/, 'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/, 'ja-JP': /^(\+?81|0)\d{1,4}[ \-]?\d{1,4}[ \-]?\d{4}$/, @@ -67,4 +68,4 @@ function isMobilePhone(str, locale) { } return false; } -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 06d7aeee1..ace881f4b 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -23,6 +23,7 @@ const phones = { 'fr-FR': /^(\+?33|0)[67]\d{8}$/, 'he-IL': /^(\+972|0)([23489]|5[0248]|77)[1-9]\d{6}/, 'hu-HU': /^(\+?36)(20|30|70)\d{7}$/, + 'lt-LT': /^(\+370|8)\d{8}$/, 'id-ID': /^(\+?62|0[1-9])[\s|\d]+$/, 'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/, 'ja-JP': /^(\+?81|0)\d{1,4}[ \-]?\d{1,4}[ \-]?\d{4}$/, diff --git a/test/validators.js b/test/validators.js index 1464aeafd..4ecd45dfc 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2837,6 +2837,24 @@ describe('Validators', function () { ], args: ['id-ID'], }); + + test({ + validator: 'isMobilePhone', + valid: [ + '+37051234567', + '851234567', + ], + invalid: [ + '+65740 123 456', + '', + 'ASDFGJKLmZXJtZtesting123', + '123456', + '740123456', + '+65640123456', + '+64210123456', + ], + args: ['lt-LT'], + }); }); it('should validate currency', function () { diff --git a/validator.js b/validator.js index 51cba9e9f..4b474afb7 100644 --- a/validator.js +++ b/validator.js @@ -1007,6 +1007,7 @@ 'fr-FR': /^(\+?33|0)[67]\d{8}$/, 'he-IL': /^(\+972|0)([23489]|5[0248]|77)[1-9]\d{6}/, 'hu-HU': /^(\+?36)(20|30|70)\d{7}$/, + 'lt-LT': /^(\+370|8)\d{8}$/, 'id-ID': /^(\+?62|0[1-9])[\s|\d]+$/, 'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/, 'ja-JP': /^(\+?81|0)\d{1,4}[ \-]?\d{1,4}[ \-]?\d{4}$/, @@ -1387,4 +1388,4 @@ return validator; -})); \ No newline at end of file +})); From c59f98fdf31f321019b5e8b6f5c21b4d9ed6d1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20=C5=BDilinskas?= Date: Tue, 6 Jun 2017 18:58:44 +0300 Subject: [PATCH 2/2] Updated readme. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1928381b9..fb97bac8a 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ Passing anything other than a string is an error. - **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-DZ', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NG', 'en-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'en-PK', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'it-IT', 'ja-JP', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sr-RS', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']`). +- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['ar-DZ', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NG', 'en-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'en-PK', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'lt-LT', 'it-IT', 'ja-JP', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sr-RS', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']`). - **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.