Skip to content

Commit

Permalink
Add isMobilePhone validation for ar-SY, isAlpha and isAlphanumeric fo…
Browse files Browse the repository at this point in the history
…r ar
  • Loading branch information
forabi committed Feb 16, 2016
1 parent a2c4471 commit 8b84882
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ If you're not sure if your input is a string, coerce it using `input + ''`.
- **contains(str, seed)** - check if the string contains the seed.
- **equals(str, comparison)** - check if the string matches the comparison.
- **isAfter(str [, date])** - check if the string is a date that's after the specified date (defaults to now).
- **isAlpha(str [, locale])** - check if the string contains only letters (a-zA-Z). Locale is one of `['en-US', 'de-DE', 'es-ES', 'fr-FR', 'nl-NL', 'pt-PT', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-ZA', 'en-ZM']`) and defaults to `en-US`.
- **isAlphanumeric(str [, locale])** - check if the string contains only letters and numbers. Locale is one of `['en-US', 'de-DE', 'es-ES', 'fr-FR', 'nl-NL', 'pt-PT', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-ZA', 'en-ZM']`) and defaults to `en-US`.
- **isAlpha(str [, locale])** - check if the string contains only letters (a-zA-Z). Locale is one of `['ar', 'en-US', 'de-DE', 'es-ES', 'fr-FR', 'nl-NL', 'pt-PT', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-ZA', 'en-ZM']`) and defaults to `en-US`.
- **isAlphanumeric(str [, locale])** - check if the string contains only letters and numbers. Locale is one of `['ar', 'en-US', 'de-DE', 'es-ES', 'fr-FR', 'nl-NL', 'pt-PT', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-ZA', 'en-ZM']`) and defaults to `en-US`.
- **isAscii(str)** - check if the string contains ASCII chars only.
- **isBase64(str)** - check if a string is base64 encoded.
- **isBefore(str [, date])** - check if the string is a date that's before the specified date.
Expand Down Expand Up @@ -74,7 +74,7 @@ If you're not sure if your input is a string, coerce it using `input + ''`.
- **isLength(str, options)** - check if the string's length falls in a range. `options` is an object which defaults to `{min:0, max: undefined}`. Note: this function takes into account surrogate pairs.
- **isLowercase(str)** - check if the string is lowercase.
- **isMACAddress(str)** - check if the string is a MAC address.
- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['zh-CN', 'zh-TW', 'en-ZA', 'en-AU', 'en-HK', 'pt-PT', 'fr-FR', 'el-GR', 'en-GB', 'en-US', 'en-ZM', 'ru-RU', 'nb-NO', 'nn-NO', 'vi-VN', 'en-NZ', 'en-IN', 'es-ES', 'de-DE', 'fi-FI']`).
- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['ar-SY', 'zh-CN', 'zh-TW', 'en-ZA', 'en-AU', 'en-HK', 'pt-PT', 'fr-FR', 'el-GR', 'en-GB', 'en-US', 'en-ZM', 'ru-RU', 'nb-NO', 'nn-NO', 'vi-VN', 'en-NZ', 'en-IN', 'es-ES', 'de-DE', 'fi-FI']`).
- **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.
- **isNull(str)** - check if the string is null.
Expand Down
6 changes: 4 additions & 2 deletions lib/alpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ var alpha = exports.alpha = {
'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'nl-NL': /^[A-ZÉËÏÓÖÜ]+$/i,
'pt-PT': /^[A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i
'pt-PT': /^[A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i,
ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/
};

var alphanumeric = exports.alphanumeric = {
Expand All @@ -18,7 +19,8 @@ var alphanumeric = exports.alphanumeric = {
'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'nl-NL': /^[0-9A-ZÉËÏÓÖÜ]+$/i,
'pt-PT': /^[0-9A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i
'pt-PT': /^[0-9A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i,
ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/
};

var englishLocales = exports.englishLocales = ['AU', 'GB', 'HK', 'IN', 'NZ', 'ZA', 'ZM'];
Expand Down
1 change: 1 addition & 0 deletions lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de

/* eslint-disable max-len */
var phones = {
'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/,
'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/,
'de-DE': /^(\+?49[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/,
'el-GR': /^(\+?30)?(69\d{8})$/,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/alpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const alpha = {
'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'nl-NL': /^[A-ZÉËÏÓÖÜ]+$/i,
'pt-PT': /^[A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i,
ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
};

export const alphanumeric = {
Expand All @@ -14,6 +15,7 @@ export const alphanumeric = {
'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'nl-NL': /^[0-9A-ZÉËÏÓÖÜ]+$/i,
'pt-PT': /^[0-9A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i,
ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
};

export const englishLocales = ['AU', 'GB', 'HK', 'IN', 'NZ', 'ZA', 'ZM'];
Expand Down
1 change: 1 addition & 0 deletions src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import assertString from './util/assertString';

/* eslint-disable max-len */
const phones = {
'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/,
'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/,
'de-DE': /^(\+?49[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/,
'el-GR': /^(\+?30)?(69\d{8})$/,
Expand Down
19 changes: 19 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,25 @@ describe('Validators', function () {
});

it('should validate mobile phone number', function () {
test({
validator: 'isMobilePhone'
, valid: [
'0944549710'
, '+963944549710'
, '956654379'
, '0944549710'
, '0962655597'
]
, invalid: [
'12345'
, ''
, '+9639626626262'
, '+963332210972'
, '0114152198'
],
args: ['ar-SY']
});

test({
validator: 'isMobilePhone'
, valid: [
Expand Down
7 changes: 5 additions & 2 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@
'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'nl-NL': /^[A-ZÉËÏÓÖÜ]+$/i,
'pt-PT': /^[A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i
'pt-PT': /^[A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i,
ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/
};

var alphanumeric = {
Expand All @@ -398,7 +399,8 @@
'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'nl-NL': /^[0-9A-ZÉËÏÓÖÜ]+$/i,
'pt-PT': /^[0-9A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i
'pt-PT': /^[0-9A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i,
ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/
};

var englishLocales = ['AU', 'GB', 'HK', 'IN', 'NZ', 'ZA', 'ZM'];
Expand Down Expand Up @@ -827,6 +829,7 @@

/* eslint-disable max-len */
var phones = {
'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/,
'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/,
'de-DE': /^(\+?49[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/,
'el-GR': /^(\+?30)?(69\d{8})$/,
Expand Down
Loading

0 comments on commit 8b84882

Please sign in to comment.