diff --git a/README.md b/README.md index c1576f892..7ad1f45ce 100644 --- a/README.md +++ b/README.md @@ -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-DZ', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', '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', 'hu-HU', '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-DZ', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', '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', 'hu-HU', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', '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). diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 2b578177f..38bba4e13 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -23,6 +23,7 @@ const phones = { '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}$/, + 'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/, 'pt-BR': /^(\+?55|0)\-?[1-9]{2}\-?[2-9]{1}\d{3,4}\-?\d{4}$/, 'pt-PT': /^(\+?351)?9[1236]\d{7}$/, 'ru-RU': /^(\+?7|8)?9\d{9}$/, diff --git a/test/validators.js b/test/validators.js index 46f8a2f30..6af9e429f 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2230,6 +2230,32 @@ describe('Validators', function () { args: ['es-ES'], }); + test({ + validator: 'isMobilePhone', + valid: [ + '+48512689767', + '+48 56 376 87 47', + '56 566 78 46', + '657562855', + '+48657562855', + '+48 887472765', + '+48 56 6572724', + '+48 67 621 5461', + '48 67 621 5461', + ], + invalid: [ + '+48 67 621 5461', + '+55657562855', + '3454535', + 'teststring', + '', + '1800-88-8687', + '+6019-5830837', + '357562855', + ], + args: ['pl-PL'], + }); + test({ validator: 'isMobilePhone', valid: [