From c0b1b3afd55254d5b3eb1a3ab25eb80221b68b70 Mon Sep 17 00:00:00 2001 From: TADOKORO Saneyuki Date: Thu, 18 Aug 2016 16:17:42 +0900 Subject: [PATCH] Add Japanese mobile phone locale --- README.md | 2 +- src/lib/isMobilePhone.js | 1 + test/validators.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 911d3b530..5ebe20203 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,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-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fi-FI', 'fr-FR', 'hu-HU', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ru-RU', 'tr-TR', 'vi-VN', 'zh-CN', '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-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fi-FI', 'fr-FR', 'hu-HU', 'ja-JP', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ru-RU', 'tr-TR', 'vi-VN', 'zh-CN', '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. - **isNull(str)** - check if the string is null (has a length of zero). diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 42db9c959..e8e249326 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -21,6 +21,7 @@ const phones = { 'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5)?|50)\s?(\d\s?){4,8}\d$/, 'fr-FR': /^(\+?33|0)[67]\d{8}$/, 'hu-HU': /^(\+?36)(20|30|70)\d{7}$/, + 'ja-JP': /^(\+?81|0)\d{1,4}[ \-]?\d{1,4}[ \-]?\d{4}$/, 'ms-MY': /^(\+?6?01){1}(([145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/, 'nb-NO': /^(\+?47)?[49]\d{7}$/, 'nn-NO': /^(\+?47)?[49]\d{7}$/, diff --git a/test/validators.js b/test/validators.js index d77b0ca7b..d4c4d9176 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2348,6 +2348,36 @@ describe('Validators', function () { ], args: ['ms-MY'], }); + + test({ + validator: 'isMobilePhone', + valid: [ + '0312345678', + '0721234567', + '09012345688', + '06 1234 5678', + '072 123 4567', + '0729 12 3456', + '07296 1 2345', + '072961 2345', + '090 1234 5678', + '03-1234-5678', + '+81312345678', + '+816-1234-5678', + '+8190-1234-5678', + ], + invalid: [ + '12345', + '', + '045555717112312332423423421', + 'Vml2YW11cyBmZXJtZtesting123', + '+3-585-0555-7171', + '0 1234 5689', + '16 1234 5689', + '03_1234_5689', + ], + args: ['ja-JP'], + }); }); it('should validate currency', function () {