From aef5aa6d874493fe4a34a3ade8aa39f84d091fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B8rn=20Mar=C3=B8?= Date: Thu, 8 Oct 2015 13:46:55 +0200 Subject: [PATCH 1/2] isMobilePhone norwegian numbers (nb-NO and nn-NO) --- test/validators.js | 32 ++++++++++++++++++++++++++++++++ validator.js | 4 +++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index 36423bcdd..e5edf38fd 100644 --- a/test/validators.js +++ b/test/validators.js @@ -1519,6 +1519,38 @@ describe('Validators', function () { ], args: ['ru-RU'] }); + + var norwegian = { + valid: [ + '+4796338855' + , '+4746338855' + , '4796338855' + , '4746338855' + , '46338855' + , '96338855' + ] + , invalid: [ + '12345' + , '' + , 'Vml2YW11cyBmZXJtZtesting123' + , '+4676338855' + , '19676338855' + , '+4726338855' + , '4736338855' + , '66338855' + ]}; + test({ + validator: 'isMobilePhone' + , valid: norwegian.valid + , invalid: norwegian.invalid, + args: ['nb-NO'] + }); + test({ + validator: 'isMobilePhone' + , valid: norwegian.valid + , invalid: norwegian.invalid, + args: ['nn-NO'] + }); }); it('should validate currency', function() { diff --git a/validator.js b/validator.js index 4290b0991..00b7ced56 100644 --- a/validator.js +++ b/validator.js @@ -90,7 +90,9 @@ 'en-GB': /^(\+?44|0)7\d{9}$/, 'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/, 'en-ZM': /^(\+26)?09[567]\d{7}$/, - 'ru-RU': /^(\+?7|8)?9\d{9}$/ + 'ru-RU': /^(\+?7|8)?9\d{9}$/, + 'nb-NO': /^(\+?47)?[49]\d{7}$/, + 'nn-NO': /^(\+?47)?[49]\d{7}$/ }; // from http://goo.gl/0ejHHW From bc6be2e0e5a6a42a7b0d078b444deabb0994f968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B8rn=20Mar=C3=B8?= Date: Thu, 8 Oct 2015 13:48:25 +0200 Subject: [PATCH 2/2] Added nb-NO and nn-NO to README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2cc70939b..a909b08b9 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ $ bower install validator-js - **isJSON(str)** - check if the string is valid JSON (note: uses JSON.parse). - **isLength(str, min [, max])** - check if the string's length falls in a range. Note: this function takes into account surrogate pairs. - **isLowercase(str)** - check if the string is lowercase. -- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['zh-CN', 'zh-TW', 'en-ZA', 'en-AU', 'en-HK', 'pt-PT', 'fr-FR', 'el-GR', 'en-GB', 'en-US', 'en-ZM', 'ru-RU']`). +- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['zh-CN', 'zh-TW', 'en-ZA', 'en-AU', 'en-HK', 'pt-PT', 'fr-FR', 'el-GR', 'en-GB', 'en-US', 'en-ZM', 'ru-RU', 'nb-NO', 'nn-NO']`). - **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.