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

feat(isMobilePhone): Added locales for several european countries #1492

Merged
merged 10 commits into from
Oct 22, 2020
5 changes: 5 additions & 0 deletions src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ const phones = {
'be-BY': /^(\+?375)?(24|25|29|33|44)\d{7}$/,
'bg-BG': /^(\+?359|0)?8[789]\d{7}$/,
'bn-BD': /^(\+?880|0)1[13456789][0-9]{8}$/,
'ca-AD': /^(\+376)?[346]\d{5}$/,
'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,
'de-DE': /^(\+49)?0?[1|3]([0|5][0-45-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/,
'de-AT': /^(\+43|0)\d{1,4}\d{3,12}$/,
'de-CH': /^(\+41|0)(7[5-9])\d{1,7}$/,
'de-LU': /^(\+352)?((6\d1)\d{6})$/,
'el-GR': /^(\+?30|0)?(69\d{8})$/,
'en-AU': /^(\+?61|0)4\d{8}$/,
'en-GB': /^(\+?44|0)7\d{9}$/,
Expand Down Expand Up @@ -77,6 +79,7 @@ const phones = {
'hu-HU': /^(\+?36)(20|30|70)\d{7}$/,
'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,
'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
'it-SM': /^((\+378)|(0549)|(\+390549)|(\+3780549))?6\d{5,9}$/,
'ja-JP': /^(\+81[ \-]?(\(0\))?|0)[6789]0[ \-]?\d{4}[ \-]?\d{4}$/,
'ka-GE': /^(\+?995)?(5|79)\d{7}$/,
'kk-KZ': /^(\+?7|8)?7\d{9}$/,
Expand All @@ -96,6 +99,7 @@ const phones = {
'ru-RU': /^(\+?7|8)?9\d{9}$/,
'sl-SI': /^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/,
'sk-SK': /^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
'sq-AL': /^(\+355|0)6[789]\d{6}$/,
'sr-RS': /^(\+3816|06)[- \d]{5,9}$/,
'sv-SE': /^(\+?46|0)[\s\-]?7[\s\-]?[02369]([\s\-]?\d){7}$/,
'th-TH': /^(\+66|66|0)\d{9}$/,
Expand All @@ -113,6 +117,7 @@ phones['en-CA'] = phones['en-US'];
phones['fr-BE'] = phones['nl-BE'];
phones['zh-HK'] = phones['en-HK'];
phones['zh-MO'] = phones['en-MO'];
phones['ga-IE'] = phones['en-IE'];

export default function isMobilePhone(str, locale, options) {
assertString(str);
Expand Down
62 changes: 62 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -7133,6 +7133,68 @@ describe('Validators', () => {
'+994778008080a',
],
},
{
locale: 'de-LU',
valid: [
'601123456',
'+352601123456',
],
invalid: [
'NaN',
'791234',
'+352791234',
'26791234',
'+35226791234',
'+112039812',
'+352703123456',
'1234',
],
},
{
locale: 'it-SM',
valid: [
'612345',
'05496123456',
'+37861234567',
'+390549612345678',
'+37805496123456789',
],
invalid: [
'61234567890',
'6123',
'1234567',
'+49123456',
'NotANumber',
],
},
{
locale: 'sq-AL',
valid: [
'067123456',
'+35567123456',
],
invalid: [
'67123456',
'06712345',
'06712345678',
'065123456',
'057123456',
'NotANumber',
],
},
{
locale: 'ca-AD',
valid: [
'+376312345',
'312345',
],
invalid: [
'31234',
'31234567',
'512345',
'NotANumber',
],
},
];

let allValid = [];
Expand Down