From d32f5bb195821a41bfe3d057a511d9a3c8b7406b Mon Sep 17 00:00:00 2001 From: viniciushvsilva <43585717+viniciushvsilva@users.noreply.github.com> Date: Wed, 15 Jul 2020 15:20:27 -0300 Subject: [PATCH 1/9] correct regex for pt-br phone numbers --- src/lib/isMobilePhone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 2362807c5..021f2ac8b 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -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}\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(9[6-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}$/, From b70668b867734b6b2b38231d13a07df384d7695e Mon Sep 17 00:00:00 2001 From: viniciushvsilva <43585717+viniciushvsilva@users.noreply.github.com> Date: Wed, 15 Jul 2020 15:40:05 -0300 Subject: [PATCH 2/9] changed tests for pt-BR mobile phone number validation --- test/validators.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/test/validators.js b/test/validators.js index 824ee3302..3577d5a1b 100755 --- a/test/validators.js +++ b/test/validators.js @@ -5174,12 +5174,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', @@ -5188,15 +5190,28 @@ 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', ], 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 95431-4567', + '+55 (11) 95431-4567', + '+551195431-4567', + '5511954314567', + '(11) 95431-4567', ], }, { From ca1a7628ea86b775d42191b27ed7b3415efd2420 Mon Sep 17 00:00:00 2001 From: viniciushvsilva <43585717+viniciushvsilva@users.noreply.github.com> Date: Wed, 15 Jul 2020 15:59:32 -0300 Subject: [PATCH 3/9] Removed valid number from invalid list of pt-br phones --- test/validators.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index 3577d5a1b..077fb1e8a 100755 --- a/test/validators.js +++ b/test/validators.js @@ -5201,7 +5201,6 @@ describe('Validators', () => { ], invalid: [ '0819876543', - '08158765432', '+55 15 7566123', '+017 123456789', '5501599623874', From 43751da37a7b9446ac8593a045d84ba0c8ae3899 Mon Sep 17 00:00:00 2001 From: viniciushvsilva <43585717+viniciushvsilva@users.noreply.github.com> Date: Wed, 15 Jul 2020 16:08:24 -0300 Subject: [PATCH 4/9] Added area code within parentheses after country code in pt-br phone numbers regex --- src/lib/isMobilePhone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 021f2ac8b..d0cd04c33 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -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': /^((\+?55\ ?[1-9]{2}\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(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[6-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}$/, From 7bee391918c09e0d1994d952587d5b530437f8eb Mon Sep 17 00:00:00 2001 From: viniciushvsilva <43585717+viniciushvsilva@users.noreply.github.com> Date: Thu, 16 Jul 2020 16:38:00 -0300 Subject: [PATCH 5/9] Numbers with 9 digits, second digit being 2-9 --- src/lib/isMobilePhone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index d0cd04c33..444de5bc1 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -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': /^((\+?55\ ?[1-9]{2}\ ?)|(\+?55\ ?\([1-9]{2}\)\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(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}$/, From b22304cbe586ad7a034055486f8efeba14d13528 Mon Sep 17 00:00:00 2001 From: viniciushvsilva <43585717+viniciushvsilva@users.noreply.github.com> Date: Fri, 14 Aug 2020 07:56:12 -0300 Subject: [PATCH 6/9] Updated tests to check on pt-br phone numbers starting with 9 and followed by 2-9 --- test/validators.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/validators.js b/test/validators.js index 077fb1e8a..7825ea335 100755 --- a/test/validators.js +++ b/test/validators.js @@ -5198,6 +5198,7 @@ describe('Validators', () => { '(22)99956-7894', '(22) 999567894', '(22) 99956-7894', + '(11) 94123-4567' ], invalid: [ '0819876543', @@ -5210,6 +5211,7 @@ describe('Validators', () => { '+55 (11) 95431-4567', '+551195431-4567', '5511954314567', + '5511912345678', '(11) 95431-4567', ], }, From 0517fa6af9f5acdae8bd44c34d9157f14a627217 Mon Sep 17 00:00:00 2001 From: viniciushvsilva <43585717+viniciushvsilva@users.noreply.github.com> Date: Fri, 14 Aug 2020 08:11:31 -0300 Subject: [PATCH 7/9] Trailing comma removed --- test/validators.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index 7825ea335..9bb388a2b 100755 --- a/test/validators.js +++ b/test/validators.js @@ -5212,7 +5212,7 @@ describe('Validators', () => { '+551195431-4567', '5511954314567', '5511912345678', - '(11) 95431-4567', + '(11) 95431-4567' ], }, { From 72581e7cf93797213881a1c5375d1f1a296a2b83 Mon Sep 17 00:00:00 2001 From: viniciushvsilva <43585717+viniciushvsilva@users.noreply.github.com> Date: Fri, 14 Aug 2020 08:15:23 -0300 Subject: [PATCH 8/9] Updated trailing comma --- test/validators.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/validators.js b/test/validators.js index 9bb388a2b..d10218656 100755 --- a/test/validators.js +++ b/test/validators.js @@ -5198,7 +5198,7 @@ describe('Validators', () => { '(22)99956-7894', '(22) 999567894', '(22) 99956-7894', - '(11) 94123-4567' + '(11) 94123-4567', ], invalid: [ '0819876543', @@ -5212,7 +5212,7 @@ describe('Validators', () => { '+551195431-4567', '5511954314567', '5511912345678', - '(11) 95431-4567' + '(11) 95431-4567', ], }, { From c445691ecdb8351d88935e7324f4c458427946e8 Mon Sep 17 00:00:00 2001 From: viniciushvsilva <43585717+viniciushvsilva@users.noreply.github.com> Date: Fri, 14 Aug 2020 08:21:27 -0300 Subject: [PATCH 9/9] Updated tests to comply with new phone numbers --- test/validators.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/validators.js b/test/validators.js index d10218656..0bfc8c9cb 100755 --- a/test/validators.js +++ b/test/validators.js @@ -5207,12 +5207,12 @@ describe('Validators', () => { '5501599623874', '+55012962308', '+55 015 1234-3214', - '+55 11 95431-4567', - '+55 (11) 95431-4567', - '+551195431-4567', - '5511954314567', + '+55 11 91431-4567', + '+55 (11) 91431-4567', + '+551191431-4567', + '5511914314567', '5511912345678', - '(11) 95431-4567', + '(11) 91431-4567', ], }, {