Skip to content

Commit 57ab6cf

Browse files
authored
Merge pull request #753 from dennis-ng/master
Added Singapore locale support to isMobilePhone
2 parents 85d40ad + 999f156 commit 57ab6cf

File tree

6 files changed

+26
-2
lines changed

6 files changed

+26
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Validator | Description
9999
**isLowercase(str)** | check if the string is lowercase.
100100
**isMACAddress(str)** | check if the string is a MAC address.
101101
**isMD5(str)** | check if the string is a MD5 hash.
102-
**isMobilePhone(str, locale)** | check if the string is a mobile phone number,<br/><br/>(locale is one of `['ar-AE', 'ar-DZ','ar-EG', 'ar-JO', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-HK', 'en-IN', 'en-KE', 'en-NG', 'en-NZ', 'en-RW', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-PK', 'es-ES', 'et-EE', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'it-IT', 'ja-JP', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', 'sr-RS', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']` OR 'any'. If 'any' is used, function will check if any of the locales match).
102+
**isMobilePhone(str, locale)** | check if the string is a mobile phone number,<br/><br/>(locale is one of `['ar-AE', 'ar-DZ','ar-EG', 'ar-JO', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-HK', 'en-IN', 'en-KE', 'en-NG', 'en-NZ', 'en-RW', 'en-SG', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-PK', 'es-ES', 'et-EE', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'it-IT', 'ja-JP', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', 'sr-RS', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']` OR 'any'. If 'any' is used, function will check if any of the locales match).
103103
**isMongoId(str)** | check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid].
104104
**isMultibyte(str)** | check if the string contains one or more multibyte chars.
105105
**isNumeric(str)** | check if the string contains only numbers.

lib/isMobilePhone.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var phones = {
3232
'en-NZ': /^(\+?64|0)2\d{7,9}$/,
3333
'en-PK': /^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$/,
3434
'en-RW': /^(\+?250|0)?[7]\d{8}$/,
35+
'en-SG': /^(\+65)?[89]\d{7}$/,
3536
'en-TZ': /^(\+?255|0)?[67]\d{8}$/,
3637
'en-UG': /^(\+?256|0)?[7]\d{8}$/,
3738
'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/,

src/lib/isMobilePhone.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const phones = {
2121
'en-NZ': /^(\+?64|0)2\d{7,9}$/,
2222
'en-PK': /^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$/,
2323
'en-RW': /^(\+?250|0)?[7]\d{8}$/,
24+
'en-SG': /^(\+65)?[89]\d{7}$/,
2425
'en-TZ': /^(\+?255|0)?[67]\d{8}$/,
2526
'en-UG': /^(\+?256|0)?[7]\d{8}$/,
2627
'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/,

test/validators.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3240,6 +3240,27 @@ describe('Validators', function () {
32403240
'08001123123',
32413241
],
32423242
},
3243+
{
3244+
locale: 'en-SG',
3245+
valid: [
3246+
'87654321',
3247+
'98765432',
3248+
'+6587654321',
3249+
'+6598765432',
3250+
],
3251+
invalid: [
3252+
'987654321',
3253+
'876543219',
3254+
'8765432',
3255+
'9876543',
3256+
'12345678',
3257+
'+98765432',
3258+
'+9876543212',
3259+
'+15673628910',
3260+
'19876543210',
3261+
'8005552222',
3262+
],
3263+
},
32433264
{
32443265
locale: 'en-US',
32453266
valid: [

validator.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,7 @@ var phones = {
979979
'en-NZ': /^(\+?64|0)2\d{7,9}$/,
980980
'en-PK': /^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$/,
981981
'en-RW': /^(\+?250|0)?[7]\d{8}$/,
982+
'en-SG': /^(\+65)?[89]\d{7}$/,
982983
'en-TZ': /^(\+?255|0)?[67]\d{8}$/,
983984
'en-UG': /^(\+?256|0)?[7]\d{8}$/,
984985
'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/,

validator.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)