Skip to content

Commit

Permalink
Merge pull request #432 from kaddopur/zh_tw_mobile
Browse files Browse the repository at this point in the history
add zh-TW locale for isMobilePhone
  • Loading branch information
chriso committed Sep 1, 2015
2 parents 21ddeb6 + e025b37 commit 3f25c47
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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', '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']`).
- **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.
Expand Down
18 changes: 18 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,24 @@ describe('Validators', function () {
args: ['zh-CN']
});

test({
validator: 'isMobilePhone'
, valid: [
'0987123456'
, '+886987123456'
, '886987123456'
, '+886-987123456'
, '886-987123456'
]
, invalid: [
'12345'
, ''
, 'Vml2YW11cyBmZXJtZtesting123'
, '0-987123456'
],
args: ['zh-TW']
});

test({
validator: 'isMobilePhone'
, invalid: [
Expand Down
1 change: 1 addition & 0 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@

var phones = {
'zh-CN': /^(\+?0?86\-?)?1[345789]\d{9}$/,
'zh-TW': /^(\+?886\-?|0)?9\d{8}$/,
'en-ZA': /^(\+?27|0)\d{9}$/,
'en-AU': /^(\+?61|0)4\d{8}$/,
'en-HK': /^(\+?852\-?)?[569]\d{3}\-?\d{4}$/,
Expand Down

0 comments on commit 3f25c47

Please sign in to comment.