Skip to content

Commit

Permalink
fix: Modify pattern of pt-Br regex
Browse files Browse the repository at this point in the history
- A Brazilian cellphone number can start with 1 after its country code and local code
- Fix test case to accept +55 11 91431-4567 and similar ones as valid

Signed-off-by: Matheus Gomes <matheusnascgomes@gmail.com>
  • Loading branch information
matheusnascgomes committed Apr 1, 2022
1 parent c1b21a9 commit 06f9919
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,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': /^((\+?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-BR': /^((\+?55\ ?[1-9]{2}\ ?)|(\+?55\ ?\([1-9]{2}\)\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(9[1-9]{1}\d{3}\-?\d{4}))$/,
'pt-PT': /^(\+?351)?9[1236]\d{7}$/,
'pt-AO': /^(\+244)\d{9}$/,
'ro-RO': /^(\+?4?0)\s?7\d{2}(\/|\s|\.|\-)?\d{3}(\s|\.|\-)?\d{3}$/,
Expand Down
18 changes: 12 additions & 6 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -6457,6 +6457,12 @@ describe('Validators', () => {
'(22) 999567894',
'(22) 99956-7894',
'(11) 94123-4567',
'(11) 91431-4567',
'+55 (11) 91431-4567',
'+55 11 91431-4567',
'+551191431-4567',
'5511914314567',
'5511912345678',
],
invalid: [
'0819876543',
Expand All @@ -6465,12 +6471,12 @@ describe('Validators', () => {
'5501599623874',
'+55012962308',
'+55 015 1234-3214',
'+55 11 91431-4567',
'+55 (11) 91431-4567',
'+551191431-4567',
'5511914314567',
'5511912345678',
'(11) 91431-4567',
'+55 11 90431-4567',
'+55 (11) 90431-4567',
'+551190431-4567',
'5511904314567',
'5511902345678',
'(11) 90431-4567',
],
},
{
Expand Down

0 comments on commit 06f9919

Please sign in to comment.