diff --git a/README.md b/README.md index 1ee230a53..4e618ee79 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/test/validators.js b/test/validators.js index 47c840c49..dccc33ca3 100644 --- a/test/validators.js +++ b/test/validators.js @@ -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' diff --git a/validator.js b/validator.js index 19bead63e..a535ecf60 100644 --- a/validator.js +++ b/validator.js @@ -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