From 9cdd111cb6132e83b0904dd3bb65d510024a71ad Mon Sep 17 00:00:00 2001 From: Hammad Javed Date: Tue, 12 Oct 2021 20:57:28 +0500 Subject: [PATCH 1/5] Fix Mobile Phone Regex Pakistan(PK) Update the regex to validate mobile numbers correctly for Pakistan --- 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 8b56b769f..b3493df5b 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -43,7 +43,7 @@ const phones = { 'en-MU': /^(\+?230|0)?\d{8}$/, 'en-NG': /^(\+?234|0)?[789]\d{9}$/, 'en-NZ': /^(\+?64|0)[28]\d{7,9}$/, - 'en-PK': /^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$/, + 'en-PK': /^((\+92)?(0092)?(92)?(0)?)(3)([0-9]{9})$/, 'en-PH': /^(09|\+639)\d{9}$/, 'en-RW': /^(\+?250|0)?[7]\d{8}$/, 'en-SG': /^(\+65)?[3689]\d{7}$/, From a7261d766510f5394666121ffb92f0020392b458 Mon Sep 17 00:00:00 2001 From: Hammad Javed Date: Tue, 12 Oct 2021 21:04:27 +0500 Subject: [PATCH 2/5] Add tests for mobile number validation locale en-PK (Pakistan) --- test/validators.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/validators.js b/test/validators.js index 91794d521..090bd7891 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7946,6 +7946,26 @@ describe('Validators', () => { 'NotANumber', ], }, + { + locale: 'en-PK', + valid: [ + '+923412877421', + '+923001234567', + '00923001234567', + '923001234567', + '03001234567', + '3001234567', + ], + invalid: [ + '+3001234567' , + '+933001234567', + '+924001234567', + '+92300123456720', + '030012345672', + '30012345673', + '0030012345673' + ], + }, ]; let allValid = []; From 9c23db60fe0e7696a23b9d070c70976de1d01f2e Mon Sep 17 00:00:00 2001 From: Hammad Javed Date: Tue, 12 Oct 2021 21:12:53 +0500 Subject: [PATCH 3/5] Linting fix --- test/validators.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/validators.js b/test/validators.js index 090bd7891..66bdb65b5 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7957,13 +7957,13 @@ describe('Validators', () => { '3001234567', ], invalid: [ - '+3001234567' , + '+3001234567', '+933001234567', '+924001234567', '+92300123456720', '030012345672', '30012345673', - '0030012345673' + '0030012345673', ], }, ]; From e48449b3e8402471966f3c461e1e415403e5de91 Mon Sep 17 00:00:00 2001 From: Hammad Javed Date: Tue, 19 Oct 2021 19:44:38 +0500 Subject: [PATCH 4/5] Update src/lib/isMobilePhone.js Update pakistan mobile regex according to suggestion Co-authored-by: Sarhan Aissi --- 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 b3493df5b..122b16bbf 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -43,7 +43,7 @@ const phones = { 'en-MU': /^(\+?230|0)?\d{8}$/, 'en-NG': /^(\+?234|0)?[789]\d{9}$/, 'en-NZ': /^(\+?64|0)[28]\d{7,9}$/, - 'en-PK': /^((\+92)?(0092)?(92)?(0)?)(3)([0-9]{9})$/, + 'en-PK': /^((00|\+)?92|0)3[0-6]\d{8}$/, 'en-PH': /^(09|\+639)\d{9}$/, 'en-RW': /^(\+?250|0)?[7]\d{8}$/, 'en-SG': /^(\+65)?[3689]\d{7}$/, From 062e394e0a0fddfcf43386109ce4a674a92e2c92 Mon Sep 17 00:00:00 2001 From: Hammad Javed Date: Tue, 19 Oct 2021 20:06:19 +0500 Subject: [PATCH 5/5] Update tests for PK phone numbers --- test/validators.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index 66bdb65b5..94eb57566 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7954,7 +7954,6 @@ describe('Validators', () => { '00923001234567', '923001234567', '03001234567', - '3001234567', ], invalid: [ '+3001234567', @@ -7964,6 +7963,7 @@ describe('Validators', () => { '030012345672', '30012345673', '0030012345673', + '3001234567', ], }, ];