Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation for Finnish phone numbers #455

Merged
merged 1 commit into from
Feb 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ All input is coerced to a string using the following rules:
- **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']`).
- **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']`).
- **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
30 changes: 30 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,36 @@ describe('Validators', function () {
});
});

test({
validator: 'isMobilePhone'
, valid: [
'+358505557171'
, '0455571'
, '0505557171'
, '00358505557171'
, '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']
});

it('should validate currency', function() {
test({
validator: 'isCurrency'
Expand Down
3 changes: 2 additions & 1 deletion validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
'en-NZ': /^(\+?64|0)2\d{7,9}$/,
'en-IN': /^(\+?91|0)?[789]\d{9}$/,
'es-ES': /^(\+34)?(6\d{1}|7[1234])\d{7}$/,
'de-DE': /^(\+?49[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/
'de-DE': /^(\+?49[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/,
'fi-FI': /^(00358|\+358|0)\s?(4|40|41|42|44|45|50)\s?(\d\s?){4,8}\d$/
};

// from http://goo.gl/0ejHHW
Expand Down