Skip to content

Commit

Permalink
Merge pull request #676 from ProfNandaa/ft-more-african-locales
Browse files Browse the repository at this point in the history
[feat: isMobilePhone] add more african locales
  • Loading branch information
chriso authored Jun 28, 2017
2 parents 0de4547 + 91c880e commit 64c6bc1
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Passing anything other than a string is an error.
- **isLowercase(str)** - check if the string is lowercase.
- **isMACAddress(str)** - check if the string is a MAC address.
- **isMD5(str)** - check if the string is a MD5 hash.
- **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-KE', 'en-NG', 'en-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'en-PK', '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', 'sr-RS', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']` OR 'any'. If 'any' is used, function will check if any of the locales match).
- **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-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', 'es-ES', 'en-PK', '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', 'sr-RS', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']` OR 'any'. If 'any' is used, function will check if any of the locales match).
- **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)** - check if the string contains only numbers.
Expand Down
3 changes: 3 additions & 0 deletions lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ var phones = {
'en-KE': /^(\+?254|0)?[7]\d{8}$/,
'en-NG': /^(\+?234|0)?[789]\d{9}$/,
'en-NZ': /^(\+?64|0)2\d{7,9}$/,
'en-UG': /^(\+?256|0)?[7]\d{8}$/,
'en-RW': /^(\+?250|0)?[7]\d{8}$/,
'en-TZ': /^(\+?255|0)?[67]\d{8}$/,
'en-ZA': /^(\+?27|0)\d{9}$/,
'en-ZM': /^(\+?26)?09[567]\d{7}$/,
'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/,
Expand Down
3 changes: 3 additions & 0 deletions src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const phones = {
'en-KE': /^(\+?254|0)?[7]\d{8}$/,
'en-NG': /^(\+?234|0)?[789]\d{9}$/,
'en-NZ': /^(\+?64|0)2\d{7,9}$/,
'en-UG': /^(\+?256|0)?[7]\d{8}$/,
'en-RW': /^(\+?250|0)?[7]\d{8}$/,
'en-TZ': /^(\+?255|0)?[67]\d{8}$/,
'en-ZA': /^(\+?27|0)\d{9}$/,
'en-ZM': /^(\+?26)?09[567]\d{7}$/,
'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/,
Expand Down
51 changes: 51 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,57 @@ describe('Validators', function () {
'+254800723845',
],
},
{
locale: 'en-UG',
valid: [
'+256728590432',
'+256733875610',
'256728590234',
'0773346543',
'0700459022',
],
invalid: [
'999',
'+254728590432',
'+25489032',
'123456789',
'+254800723845',
],
},
{
locale: 'en-RW',
valid: [
'+250728590432',
'+250733875610',
'250738590234',
'0753346543',
'0780459022',
],
invalid: [
'999',
'+254728590432',
'+25089032',
'123456789',
'+250800723845',
],
},
{
locale: 'en-TZ',
valid: [
'+255728590432',
'+255733875610',
'255628590234',
'0673346543',
'0600459022',
],
invalid: [
'999',
'+254728590432',
'+25589032',
'123456789',
'+255800723845',
],
},
{
locale: 'fr-FR',
valid: [
Expand Down
3 changes: 3 additions & 0 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,9 @@ var phones = {
'en-KE': /^(\+?254|0)?[7]\d{8}$/,
'en-NG': /^(\+?234|0)?[789]\d{9}$/,
'en-NZ': /^(\+?64|0)2\d{7,9}$/,
'en-UG': /^(\+?256|0)?[7]\d{8}$/,
'en-RW': /^(\+?250|0)?[7]\d{8}$/,
'en-TZ': /^(\+?255|0)?[67]\d{8}$/,
'en-ZA': /^(\+?27|0)\d{9}$/,
'en-ZM': /^(\+?26)?09[567]\d{7}$/,
'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/,
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit 64c6bc1

Please sign in to comment.