Skip to content

Commit af36196

Browse files
feat(isMobilePhone): add support for Philippines locale (#1388)
* Update isMobilePhone.js (#1) Add support for Philippine mobile no. * chore: add locale on readme * refactor: remove en-PH validation for isMobilePhone * feat: add Philippines mobile number validation * feat: add test case for en-PH phone number * chore: generate update * refactor: add support for domestic ph numbers
1 parent bb7b211 commit af36196

File tree

9 files changed

+42
-3
lines changed

9 files changed

+42
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Validator | Description
136136
**isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme).
137137
**isMD5(str)** | check if the string is a MD5 hash.<br/><br/>Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA).
138138
**isMimeType(str)** | check if the string matches to a valid [MIME type](https://en.wikipedia.org/wiki/Media_type) format
139-
**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,<br/><br/>(locale is either an array of locales (e.g `['sk-SK', 'sr-RS']`) OR one of `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW' , 'es-CL', 'es-CO', 'es-CR', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ro-RO', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', 'zh-TW']` OR defaults to 'any'. If 'any' or a falsey value is used, function will check if any of the locales match).<br/><br/>`options` is an optional object that can be supplied with the following keys: `strictMode`, if this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`. Locale list is `validator.isMobilePhoneLocales`.
139+
**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,<br/><br/>(locale is either an array of locales (e.g `['sk-SK', 'sr-RS']`) OR one of `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW' , 'es-CL', 'es-CO', 'es-CR', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ro-RO', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', 'zh-TW']` OR defaults to 'any'. If 'any' or a falsey value is used, function will check if any of the locales match).<br/><br/>`options` is an optional object that can be supplied with the following keys: `strictMode`, if this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`. Locale list is `validator.isMobilePhoneLocales`.
140140
**isMongoId(str)** | check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid].
141141
**isMultibyte(str)** | check if the string contains one or more multibyte chars.
142142
**isNumeric(str [, options])** | check if the string contains only numbers.<br/><br/>`options` is an object which defaults to `{no_symbols: false}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).<br/><br/>`locale` determine the decimal separator and is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`.

es/lib/isIdentityCard.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ var validators = {
4242
});
4343
return c === 0;
4444
},
45+
IT: function IT(str) {
46+
if (str.length !== 9) return false;
47+
if (str === 'CA00000AA') return false; // https://it.wikipedia.org/wiki/Carta_d%27identit%C3%A0_elettronica_italiana
48+
49+
return str.search(/C[A-Z][0-9]{5}[A-Z]{2}/i) > -1;
50+
},
4551
NO: function NO(str) {
4652
var sanitized = str.trim();
4753
if (isNaN(Number(sanitized))) return false;

es/lib/isMobilePhone.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var phones = {
3838
'en-NG': /^(\+?234|0)?[789]\d{9}$/,
3939
'en-NZ': /^(\+?64|0)[28]\d{7,9}$/,
4040
'en-PK': /^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$/,
41+
'en-PH': /^(09|\+639)\d{9}$/,
4142
'en-RW': /^(\+?250|0)?[7]\d{8}$/,
4243
'en-SG': /^(\+65)?[689]\d{7}$/,
4344
'en-SL': /^(?:0|94|\+94)?(7(0|1|2|5|6|7|8)( |-)?\d)\d{6}$/,

lib/isIdentityCard.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ var validators = {
5252
});
5353
return c === 0;
5454
},
55+
IT: function IT(str) {
56+
if (str.length !== 9) return false;
57+
if (str === 'CA00000AA') return false; // https://it.wikipedia.org/wiki/Carta_d%27identit%C3%A0_elettronica_italiana
58+
59+
return str.search(/C[A-Z][0-9]{5}[A-Z]{2}/i) > -1;
60+
},
5561
NO: function NO(str) {
5662
var sanitized = str.trim();
5763
if (isNaN(Number(sanitized))) return false;
@@ -279,4 +285,4 @@ function isIdentityCard(str, locale) {
279285
}
280286

281287
module.exports = exports.default;
282-
module.exports.default = exports.default;
288+
module.exports.default = exports.default;

lib/isMobilePhone.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var phones = {
4848
'en-NG': /^(\+?234|0)?[789]\d{9}$/,
4949
'en-NZ': /^(\+?64|0)[28]\d{7,9}$/,
5050
'en-PK': /^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$/,
51+
'en-PH': /^(09|\+639)\d{9}$/,
5152
'en-RW': /^(\+?250|0)?[7]\d{8}$/,
5253
'en-SG': /^(\+65)?[689]\d{7}$/,
5354
'en-SL': /^(?:0|94|\+94)?(7(0|1|2|5|6|7|8)( |-)?\d)\d{6}$/,

src/lib/isMobilePhone.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const phones = {
3838
'en-NG': /^(\+?234|0)?[789]\d{9}$/,
3939
'en-NZ': /^(\+?64|0)[28]\d{7,9}$/,
4040
'en-PK': /^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$/,
41+
'en-PH': /^(09|\+639)\d{9}$/,
4142
'en-RW': /^(\+?250|0)?[7]\d{8}$/,
4243
'en-SG': /^(\+65)?[689]\d{7}$/,
4344
'en-SL': /^(?:0|94|\+94)?(7(0|1|2|5|6|7|8)( |-)?\d)\d{6}$/,

test/validators.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5460,6 +5460,23 @@ describe('Validators', () => {
54605460
'+35610000000',
54615461
],
54625462
},
5463+
{
5464+
locale: 'en-PH',
5465+
valid: [
5466+
'+639275149120',
5467+
'+639275142327',
5468+
'+639003002023',
5469+
'09275149116',
5470+
'09194877624',
5471+
],
5472+
invalid: [
5473+
'12112-13-345',
5474+
'12345678901',
5475+
'sx23YW11cyBmZxxXJt123123',
5476+
'010-38238383',
5477+
'966684123123-2590',
5478+
],
5479+
},
54635480
{
54645481
locale: 'en-UG',
54655482
valid: [

validator.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,6 +1778,12 @@ var validators = {
17781778
});
17791779
return c === 0;
17801780
},
1781+
IT: function IT(str) {
1782+
if (str.length !== 9) return false;
1783+
if (str === 'CA00000AA') return false; // https://it.wikipedia.org/wiki/Carta_d%27identit%C3%A0_elettronica_italiana
1784+
1785+
return str.search(/C[A-Z][0-9]{5}[A-Z]{2}/i) > -1;
1786+
},
17811787
NO: function NO(str) {
17821788
var sanitized = str.trim();
17831789
if (isNaN(Number(sanitized))) return false;
@@ -2288,6 +2294,7 @@ var phones = {
22882294
'en-NG': /^(\+?234|0)?[789]\d{9}$/,
22892295
'en-NZ': /^(\+?64|0)[28]\d{7,9}$/,
22902296
'en-PK': /^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$/,
2297+
'en-PH': /^(09|\+639)\d{9}$/,
22912298
'en-RW': /^(\+?250|0)?[7]\d{8}$/,
22922299
'en-SG': /^(\+65)?[689]\d{7}$/,
22932300
'en-SL': /^(?:0|94|\+94)?(7(0|1|2|5|6|7|8)( |-)?\d)\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)