Skip to content

Commit 427806e

Browse files
committed
Merge pull request #439 from tormaroe/norwegian-phone-numbers
Norwegian phone numbers
2 parents a5d3874 + bc6be2e commit 427806e

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ $ bower install validator-js
6464
- **isJSON(str)** - check if the string is valid JSON (note: uses JSON.parse).
6565
- **isLength(str, min [, max])** - check if the string's length falls in a range. Note: this function takes into account surrogate pairs.
6666
- **isLowercase(str)** - check if the string is lowercase.
67-
- **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']`).
67+
- **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']`).
6868
- **isMongoId(str)** - check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid].
6969
- **isMultibyte(str)** - check if the string contains one or more multibyte chars.
7070
- **isNull(str)** - check if the string is null.

test/validators.js

+32
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,38 @@ describe('Validators', function () {
15191519
],
15201520
args: ['ru-RU']
15211521
});
1522+
1523+
var norwegian = {
1524+
valid: [
1525+
'+4796338855'
1526+
, '+4746338855'
1527+
, '4796338855'
1528+
, '4746338855'
1529+
, '46338855'
1530+
, '96338855'
1531+
]
1532+
, invalid: [
1533+
'12345'
1534+
, ''
1535+
, 'Vml2YW11cyBmZXJtZtesting123'
1536+
, '+4676338855'
1537+
, '19676338855'
1538+
, '+4726338855'
1539+
, '4736338855'
1540+
, '66338855'
1541+
]};
1542+
test({
1543+
validator: 'isMobilePhone'
1544+
, valid: norwegian.valid
1545+
, invalid: norwegian.invalid,
1546+
args: ['nb-NO']
1547+
});
1548+
test({
1549+
validator: 'isMobilePhone'
1550+
, valid: norwegian.valid
1551+
, invalid: norwegian.invalid,
1552+
args: ['nn-NO']
1553+
});
15221554
});
15231555

15241556
it('should validate currency', function() {

validator.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@
9090
'en-GB': /^(\+?44|0)7\d{9}$/,
9191
'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/,
9292
'en-ZM': /^(\+26)?09[567]\d{7}$/,
93-
'ru-RU': /^(\+?7|8)?9\d{9}$/
93+
'ru-RU': /^(\+?7|8)?9\d{9}$/,
94+
'nb-NO': /^(\+?47)?[49]\d{7}$/,
95+
'nn-NO': /^(\+?47)?[49]\d{7}$/
9496
};
9597

9698
// from http://goo.gl/0ejHHW

0 commit comments

Comments
 (0)