Skip to content

Commit

Permalink
Add an en-CA alias to isMobilePhone, closes #524
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed May 28, 2016
1 parent 836b2df commit e61cdce
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
([#532](https://github.com/chriso/validator.js/pull/532))
- Adjust Chinese mobile phone validation
([#523](https://github.com/chriso/validator.js/pull/523))
- Added a Canadian locale to `isMobilePhone()`
([#524](https://github.com/chriso/validator.js/issues/524))

#### 5.2.0

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Passing anything other than a string is an error.
- **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 `['ar-SY', 'cs-CZ', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fi-FI', 'fr-FR', 'ms-MY', 'nb-NO', 'nn-NO', 'pt-PT', 'ru-RU', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-TW']`).
- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['ar-SY', 'cs-CZ', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fi-FI', 'fr-FR', 'ms-MY', 'nb-NO', 'nn-NO', 'pt-PT', 'ru-RU', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-TW']`).
- **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 (has a length of zero).
Expand Down
3 changes: 3 additions & 0 deletions lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ var phones = {
};
/* eslint-enable max-len */

// aliases
phones['en-CA'] = phones['en-US'];

function isMobilePhone(str, locale) {
(0, _assertString2.default)(str);
if (locale in phones) {
Expand Down
3 changes: 3 additions & 0 deletions src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const phones = {
};
/* eslint-enable max-len */

// aliases
phones['en-CA'] = phones['en-US'];

export default function isMobilePhone(str, locale) {
assertString(str);
if (locale in phones) {
Expand Down
19 changes: 19 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,25 @@ describe('Validators', function () {
],
args: ['en-US'],
});
test({
validator: 'isMobilePhone',
valid: [
'19876543210',
'8005552222',
'+15673628910',
],
invalid: [
'564785',
'0123456789',
'1437439210',
'8009112340',
'+10345672645',
'11435213543',
'2436119753',
'16532116190',
],
args: ['en-CA'],
});

test({
validator: 'isMobilePhone',
Expand Down
3 changes: 3 additions & 0 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,9 @@
};
/* eslint-enable max-len */

// aliases
phones['en-CA'] = phones['en-US'];

function isMobilePhone(str, locale) {
assertString(str);
if (locale in phones) {
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit e61cdce

Please sign in to comment.