Skip to content

Commit

Permalink
fix(isMobilePhone): fixed pt-br locale (#1407)
Browse files Browse the repository at this point in the history
* correct regex for pt-br phone numbers

* changed tests for pt-BR mobile phone number validation

* Removed valid number from invalid list of pt-br phones

* Added area code within parentheses after country code in pt-br phone numbers regex

* Numbers with 9 digits, second digit being 2-9

* Updated tests to check on pt-br phone numbers starting with 9 and followed by 2-9

* Trailing comma removed

* Updated trailing comma

* Updated tests to comply with new phone numbers
  • Loading branch information
viniciushvsilva authored Oct 21, 2020
1 parent 39f2bdc commit 73ce41d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,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 @@ -5429,12 +5429,14 @@ describe('Validators', () => {
{
locale: 'pt-BR',
valid: [
'+55-12-996551215',
'+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 @@ -5443,15 +5445,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

0 comments on commit 73ce41d

Please sign in to comment.