Skip to content

Commit 47443d1

Browse files
fix: Modify pattern of pt-Br regex (#1951)
- 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 <[email protected]>
1 parent 73098eb commit 47443d1

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/lib/isMobilePhone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const phones = {
114114
'nl-NL': /^(((\+|00)?31\(0\))|((\+|00)?31)|0)6{1}\d{8}$/,
115115
'nn-NO': /^(\+?47)?[49]\d{7}$/,
116116
'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,
117-
'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}))$/,
117+
'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}))$/,
118118
'pt-PT': /^(\+?351)?9[1236]\d{7}$/,
119119
'pt-AO': /^(\+244)\d{9}$/,
120120
'ro-RO': /^(\+?4?0)\s?7\d{2}(\/|\s|\.|\-)?\d{3}(\s|\.|\-)?\d{3}$/,

test/validators.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6476,6 +6476,12 @@ describe('Validators', () => {
64766476
'(22) 999567894',
64776477
'(22) 99956-7894',
64786478
'(11) 94123-4567',
6479+
'(11) 91431-4567',
6480+
'+55 (11) 91431-4567',
6481+
'+55 11 91431-4567',
6482+
'+551191431-4567',
6483+
'5511914314567',
6484+
'5511912345678',
64796485
],
64806486
invalid: [
64816487
'0819876543',
@@ -6484,12 +6490,12 @@ describe('Validators', () => {
64846490
'5501599623874',
64856491
'+55012962308',
64866492
'+55 015 1234-3214',
6487-
'+55 11 91431-4567',
6488-
'+55 (11) 91431-4567',
6489-
'+551191431-4567',
6490-
'5511914314567',
6491-
'5511912345678',
6492-
'(11) 91431-4567',
6493+
'+55 11 90431-4567',
6494+
'+55 (11) 90431-4567',
6495+
'+551190431-4567',
6496+
'5511904314567',
6497+
'5511902345678',
6498+
'(11) 90431-4567',
64936499
],
64946500
},
64956501
{

0 commit comments

Comments
 (0)