Skip to content

Commit f5fcb6d

Browse files
authored
Merge pull request #777 from athivvat/support-thailand-locale
Add Thailand locale support to IsMobilePhone
2 parents ab898d5 + cbea0c7 commit f5fcb6d

File tree

6 files changed

+19
-2
lines changed

6 files changed

+19
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Validator | Description
100100
**isMACAddress(str)** | check if the string is a MAC address.
101101
**isMD5(str)** | check if the string is a MD5 hash.
102102
**isMimeType(str)** | check if the string matches to a valid [MIME type](https://en.wikipedia.org/wiki/Media_type) format
103-
**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', 'bg-BG', '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', 'pt-BR', '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).
103+
**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', 'bg-BG', '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', 'pt-BR', 'ro-RO', 'ru-RU', 'sk-SK', 'sr-RS', 'th-TH', '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).
104104
**isMongoId(str)** | check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid].
105105
**isMultibyte(str)** | check if the string contains one or more multibyte chars.
106106
**isNumeric(str)** | check if the string contains only numbers.

lib/isMobilePhone.js

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ var phones = {
6464
'ru-RU': /^(\+?7|8)?9\d{9}$/,
6565
'sk-SK': /^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
6666
'sr-RS': /^(\+3816|06)[- \d]{5,9}$/,
67+
'th-TH': /^(\+66|66|0)\d{9}$/,
6768
'tr-TR': /^(\+?90|0)?5\d{9}$/,
6869
'uk-UA': /^(\+?38|8)?0\d{9}$/,
6970
'vi-VN': /^(\+?84|0)?((1(2([0-9])|6([2-9])|88|99))|(9((?!5)[0-9])))([0-9]{7})$/,

src/lib/isMobilePhone.js

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const phones = {
5353
'ru-RU': /^(\+?7|8)?9\d{9}$/,
5454
'sk-SK': /^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
5555
'sr-RS': /^(\+3816|06)[- \d]{5,9}$/,
56+
'th-TH': /^(\+66|66|0)\d{9}$/,
5657
'tr-TR': /^(\+?90|0)?5\d{9}$/,
5758
'uk-UA': /^(\+?38|8)?0\d{9}$/,
5859
'vi-VN': /^(\+?84|0)?((1(2([0-9])|6([2-9])|88|99))|(9((?!5)[0-9])))([0-9]{7})$/,

test/validators.js

+14
Original file line numberDiff line numberDiff line change
@@ -4017,6 +4017,20 @@ describe('Validators', function () {
40174017
'12 34 56 78',
40184018
],
40194019
},
4020+
{
4021+
locale: 'th-TH',
4022+
valid: [
4023+
'0912345678',
4024+
'+66912345678',
4025+
'66912345678',
4026+
],
4027+
invalid: [
4028+
'99123456789',
4029+
'12345',
4030+
'67812345623',
4031+
'081234567891',
4032+
],
4033+
},
40204034
];
40214035

40224036
var allValid = [];

validator.js

+1
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ var phones = {
10171017
'ru-RU': /^(\+?7|8)?9\d{9}$/,
10181018
'sk-SK': /^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
10191019
'sr-RS': /^(\+3816|06)[- \d]{5,9}$/,
1020+
'th-TH': /^(\+66|66|0)\d{9}$/,
10201021
'tr-TR': /^(\+?90|0)?5\d{9}$/,
10211022
'uk-UA': /^(\+?38|8)?0\d{9}$/,
10221023
'vi-VN': /^(\+?84|0)?((1(2([0-9])|6([2-9])|88|99))|(9((?!5)[0-9])))([0-9]{7})$/,

validator.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)