From 050a424e1bda06a06b1f5e4a5ca1dd1d9a8ceea4 Mon Sep 17 00:00:00 2001 From: Hammad Javed Date: Sat, 30 Oct 2021 11:22:38 +0500 Subject: [PATCH] fix(isMobilePhone): regex for Pakistan(PK) (#1778) * Fix Mobile Phone Regex Pakistan(PK) Update the regex to validate mobile numbers correctly for Pakistan * Add tests for mobile number validation locale en-PK (Pakistan) * Linting fix * Update src/lib/isMobilePhone.js Update pakistan mobile regex according to suggestion Co-authored-by: Sarhan Aissi * Update tests for PK phone numbers Co-authored-by: Sarhan Aissi --- src/lib/isMobilePhone.js | 2 +- test/validators.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 1700200b6..8563d3b51 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': /^((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}$/, diff --git a/test/validators.js b/test/validators.js index 64aa67d25..367c73e7d 100644 --- a/test/validators.js +++ b/test/validators.js @@ -8056,6 +8056,26 @@ describe('Validators', () => { 'NotANumber', ], }, + { + locale: 'en-PK', + valid: [ + '+923412877421', + '+923001234567', + '00923001234567', + '923001234567', + '03001234567', + ], + invalid: [ + '+3001234567', + '+933001234567', + '+924001234567', + '+92300123456720', + '030012345672', + '30012345673', + '0030012345673', + '3001234567', + ], + }, ]; let allValid = [];