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

Fixed mobile phone validation for pt-br #1407

Merged
merged 9 commits into from
Oct 21, 2020
2 changes: 1 addition & 1 deletion src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const phones = {
'nl-NL': /^(((\+|00)?31\(0\))|((\+|00)?31)|0)6{1}\d{8}$/,
'nn-NO': /^(\+?47)?[49]\d{7}$/,
'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,
'pt-BR': /(?=^(\+?5{2}\-?|0)[1-9]{2}\-?\d{4}\-?\d{4}$)(^(\+?5{2}\-?|0)[1-9]{2}\-?[6-9]{1}\d{3}\-?\d{4}$)|(^(\+?5{2}\-?|0)[1-9]{2}\-?9[6-9]{1}\d{3}\-?\d{4}$)/,
'pt-BR': /^((\+?55\ ?[1-9]{2}\ ?)|(\+?55\ ?\([1-9]{2}\)\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(9[2-9]{1}\d{3}\-?\d{4}))$/,
'pt-PT': /^(\+?351)?9[1236]\d{7}$/,
'ro-RO': /^(\+?4?0)\s?7\d{2}(\/|\s|\.|\-)?\d{3}(\s|\.|\-)?\d{3}$/,
'ru-RU': /^(\+?7|8)?9\d{9}$/,
Expand Down
36 changes: 26 additions & 10 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -5174,12 +5174,14 @@ describe('Validators', () => {
{
locale: 'pt-BR',
valid: [
'+55-12-996551215',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain this regression?

Copy link

@lunatupini lunatupini Oct 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brazilian numbers never use dashes between numbers.

'+55-15-97661234',
'55-17-96332-2155',
'55-17-6332-2155',
'55-15-976612345',
'55-15-75661234',
'+55 12 996551215',
'+55 15 97661234',
'+55 (12) 996551215',
'+55 (15) 97661234',
'55 (17) 96332-2155',
'55 (17) 6332-2155',
'55 15 976612345',
'55 15 75661234',
'+5512984567890',
'+551283456789',
'5512984567890',
Expand All @@ -5188,15 +5190,29 @@ describe('Validators', () => {
'01593456987',
'022995678947',
'02299567894',
'(22)99567894',
'(22)9956-7894',
'(22) 99567894',
'(22) 9956-7894',
'(22)999567894',
'(22)99956-7894',
'(22) 999567894',
'(22) 99956-7894',
'(11) 94123-4567',
],
invalid: [
'0819876543',
'08158765432',
'+55-15-7566123',
'+017-123456789',
'+55 15 7566123',
'+017 123456789',
'5501599623874',
'+55012962308',
'+55-015-1234-3214',
'+55 015 1234-3214',
'+55 11 91431-4567',
'+55 (11) 91431-4567',
'+551191431-4567',
'5511914314567',
'5511912345678',
'(11) 91431-4567',
],
},
{
Expand Down