Skip to content

Commit

Permalink
Merge branch 'paragasu-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Feb 25, 2016
2 parents 7742d69 + f066fe2 commit 328cd7a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,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', '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', 'ms-MY']`).
- **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
1 change: 1 addition & 0 deletions lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var phones = {
'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/,
'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5)?|50)\s?(\d\s?){4,8}\d$/,
'fr-FR': /^(\+?33|0)[67]\d{8}$/,
'ms-MY': /^(\+?6?01){1}(([145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,
'nb-NO': /^(\+?47)?[49]\d{7}$/,
'nn-NO': /^(\+?47)?[49]\d{7}$/,
'pt-BR': /^(\+?55|0)\-?[1-9]{2}\-?[2-9]{1}\d{3,4}\-?\d{4}$/,
Expand Down
1 change: 1 addition & 0 deletions src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const phones = {
'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/,
'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5)?|50)\s?(\d\s?){4,8}\d$/,
'fr-FR': /^(\+?33|0)[67]\d{8}$/,
'ms-MY': /^(\+?6?01){1}(([145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,
'nb-NO': /^(\+?47)?[49]\d{7}$/,
'nn-NO': /^(\+?47)?[49]\d{7}$/,
'pt-BR': /^(\+?55|0)\-?[1-9]{2}\-?[2-9]{1}\d{3,4}\-?\d{4}$/,
Expand Down
84 changes: 55 additions & 29 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -2063,36 +2063,62 @@ describe('Validators', function () {
],
args: ['es-ES'],
});
});

test({
validator: 'isMobilePhone',
valid: [
'+358505557171',
'0455571',
'0505557171',
'358505557171',
'04412345',
'0457 123 45 67',
'+358457 123 45 67',
'+358 50 555 7171',
],
invalid: [
'12345',
'',
'045557',
'045555717112312332423423421',
'Vml2YW11cyBmZXJtZtesting123',
'010-38238383',
'+3-585-0555-7171',
'+9676338855',
'19676338855',
'6676338855',
'+99676338855',
'044123',
'019123456789012345678901',
],
args: ['fi-FI'],
test({
validator: 'isMobilePhone',
valid: [
'+358505557171',
'0455571',
'0505557171',
'358505557171',
'04412345',
'0457 123 45 67',
'+358457 123 45 67',
'+358 50 555 7171',
],
invalid: [
'12345',
'',
'045557',
'045555717112312332423423421',
'Vml2YW11cyBmZXJtZtesting123',
'010-38238383',
'+3-585-0555-7171',
'+9676338855',
'19676338855',
'6676338855',
'+99676338855',
'044123',
'019123456789012345678901',
],
args: ['fi-FI'],
});

test({
validator: 'isMobilePhone',
valid: [
'+60128228789',
'+60195830837',
'+6019-5830837',
'+6019-5830837',
'0128737867',
'01468987837',
'016-2838768',
'016 2838768',
],
invalid: [
'12345',
'601238788657',
'088387675',
'16-2838768',
'032551433',
'6088-387888',
'088-261987',
'1800-88-8687',
'088-320000',
],
args: ['ms-MY'],
});
});

it('should validate currency', function () {
Expand Down
1 change: 1 addition & 0 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@
'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/,
'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5)?|50)\s?(\d\s?){4,8}\d$/,
'fr-FR': /^(\+?33|0)[67]\d{8}$/,
'ms-MY': /^(\+?6?01){1}(([145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,
'nb-NO': /^(\+?47)?[49]\d{7}$/,
'nn-NO': /^(\+?47)?[49]\d{7}$/,
'pt-BR': /^(\+?55|0)\-?[1-9]{2}\-?[2-9]{1}\d{3,4}\-?\d{4}$/,
Expand Down
Loading

0 comments on commit 328cd7a

Please sign in to comment.