From 5a1cd69f308d97e92b485ed394e077401d15a28a Mon Sep 17 00:00:00 2001 From: Lawrence Aberba Date: Tue, 30 Oct 2018 19:02:18 +0000 Subject: [PATCH 1/3] Update validators.js Add tests for Ghana phone codes --- test/validators.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/validators.js b/test/validators.js index 888492a38..b154ab8e1 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3672,6 +3672,37 @@ describe('Validators', () => { '+0821231234', '04123456789', ], + }, + { + locale: 'en-GH', + valid: [ + '0202345671', + '0502345671', + '0242345671', + '0542345671', + '0272345671', + '0572345671', + '0262345671', + '0562345671', + '0232345671', + '0282345671', + '+233202345671', + '+233502345671', + '+233242345671', + '+233542345671', + '+233272345671', + '+233572345671', + '+233262345671', + '+233562345671', + '+233232345671', + '+233282345671', + ], + invalid: [ + '082123', + '232345671', + '0232345671', + '+233232345671', + ], }, { locale: 'en-HK', From 758688797346e469760050b524d85d84f9ad8599 Mon Sep 17 00:00:00 2001 From: Lawrence Aberba Date: Tue, 30 Oct 2018 19:38:50 +0000 Subject: [PATCH 2/3] Update isMobilePhone.js Add Ghana phone number validation regex --- lib/isMobilePhone.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/isMobilePhone.js b/lib/isMobilePhone.js index 72d246a8f..5eeafdda3 100644 --- a/lib/isMobilePhone.js +++ b/lib/isMobilePhone.js @@ -30,6 +30,7 @@ var phones = { 'el-GR': /^(\+?30|0)?(69\d{8})$/, 'en-AU': /^(\+?61|0)4\d{8}$/, 'en-GB': /^(\+?44|0)7\d{9}$/, + 'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28)\d{7}$/, 'en-HK': /^(\+?852\-?)?[456789]\d{3}\-?\d{4}$/, 'en-IN': /^(\+?91|0)?[6789]\d{9}$/, 'en-KE': /^(\+?254|0)?[7]\d{8}$/, @@ -126,4 +127,4 @@ function isMobilePhone(str, locale, options) { } var locales = Object.keys(phones); -exports.locales = locales; \ No newline at end of file +exports.locales = locales; From f90e93a46ef7fa58663c79ced1de2dbb2dffe884 Mon Sep 17 00:00:00 2001 From: Lawrence Aberba Date: Tue, 30 Oct 2018 19:44:30 +0000 Subject: [PATCH 3/3] Update README.md add Ghana phone code --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3080ee4bb..1a8e24c58 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ Validator | Description **isMACAddress(str)** | check if the string is a MAC address.

`options` is an object which defaults to `{no_colons: false}`. If `no_colons` is true, the validator will allow MAC addresses without the colons. **isMD5(str)** | check if the string is a MD5 hash. **isMimeType(str)** | check if the string matches to a valid [MIME type](https://en.wikipedia.org/wiki/Media_type) format -**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,

(locale is either an array of locales (e.g `['sk-SK', 'sr-RS']`) OR one of `['ar-AE', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'be-BY', 'bg-BG', 'bn-BD', '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', 'es-MX', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'it-IT', 'ja-JP', 'kk-KZ', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'pt-BR', '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-TW']` OR defaults to 'any'. If 'any' or a falsey value is used, function will check if any of the locales match).

`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`. +**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,

(locale is either an array of locales (e.g `['sk-SK', 'sr-RS']`) OR one of `['ar-AE', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-SA', 'ar-SY', 'ar-TN', 'be-BY', 'bg-BG', 'bn-BD', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GH', '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', 'es-MX', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'it-IT', 'ja-JP', 'kk-KZ', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'pt-BR', '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-TW']` OR defaults to 'any'. If 'any' or a falsey value is used, function will check if any of the locales match).

`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`. **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. **isNumeric(str [, options])** | check if the string contains only numbers.

`options` is an object which defaults to `{no_symbols: false}`. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).