Skip to content

Commit d0a02cb

Browse files
authored
Merge pull request #559 from shanavas786/ar-sa-mobilephone
Saudi Arabia (ar-SA) Mobile Number Validation
2 parents e310a87 + f8bf977 commit d0a02cb

File tree

6 files changed

+24
-2
lines changed

6 files changed

+24
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Passing anything other than a string is an error.
8686
- **isLowercase(str)** - check if the string is lowercase.
8787
- **isMACAddress(str)** - check if the string is a MAC address.
8888
- **isMD5(str)** - check if the string is a MD5 hash.
89-
- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['ar-DZ', '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']`).
89+
- **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']`).
9090
- **isMongoId(str)** - check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid].
9191
- **isMultibyte(str)** - check if the string contains one or more multibyte chars.
9292
- **isNull(str)** - check if the string is null (has a length of zero).

lib/isMobilePhone.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
1515
var phones = {
1616
'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/,
1717
'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/,
18+
'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/,
1819
'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/,
1920
'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
2021
'de-DE': /^(\+?49[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/,

src/lib/isMobilePhone.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import assertString from './util/assertString';
44
const phones = {
55
'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/,
66
'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/,
7+
'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/,
78
'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/,
89
'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
910
'de-DE': /^(\+?49[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/,

test/validators.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,25 @@ describe('Validators', function () {
18381838
args: ['ar-SY'],
18391839
});
18401840

1841+
test({
1842+
validator: 'isMobilePhone',
1843+
valid: [
1844+
'0556578654',
1845+
'+966556578654',
1846+
'966556578654',
1847+
'596578654',
1848+
'572655597',
1849+
],
1850+
invalid: [
1851+
'12345',
1852+
'',
1853+
'+9665626626262',
1854+
'+96633221097',
1855+
'0114152198',
1856+
],
1857+
args: ['ar-SA'],
1858+
});
1859+
18411860
test({
18421861
validator: 'isMobilePhone',
18431862
valid: [

validator.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@
869869
var phones = {
870870
'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/,
871871
'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/,
872+
'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/,
872873
'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/,
873874
'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
874875
'de-DE': /^(\+?49[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/,

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)