From 677c3b7e57a89898bd8155e744d528677c46be70 Mon Sep 17 00:00:00 2001 From: ward khaddour Date: Sun, 20 Apr 2025 18:35:42 +0300 Subject: [PATCH 1/2] add qatar phone numbers validation create ar-QA field in phones object with correct regex added isMobilePhone.test.js file with test cases for qatar mobile phones --- src/lib/isMobilePhone.js | 2 + test/validators/isMobilePhone.test.js | 102 ++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 test/validators/isMobilePhone.test.js diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index ec1483d65..5e0f4d869 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -20,6 +20,7 @@ const phones = { 'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/, 'ar-TN': /^(\+?216)?[2459]\d{7}$/, 'az-AZ': /^(\+994|0)(10|5[015]|7[07]|99)\d{7}$/, + 'ar-QA': /^(\+?974\s?)?([3567]\d{3})(\s|-)?\d{4}$/, 'bs-BA': /^((((\+|00)3876)|06))((([0-3]|[5-6])\d{6})|(4\d{7}))$/, 'be-BY': /^(\+?375)?(24|25|29|33|44)\d{7}$/, 'bg-BG': /^(\+?359|0)?8[789]\d{7}$/, @@ -173,6 +174,7 @@ phones['zh-MO'] = phones['en-MO']; phones['ga-IE'] = phones['en-IE']; phones['fr-CH'] = phones['de-CH']; phones['it-CH'] = phones['fr-CH']; +phones['en-QA'] = phones['ar-QA']; export default function isMobilePhone(str, locale, options) { assertString(str); diff --git a/test/validators/isMobilePhone.test.js b/test/validators/isMobilePhone.test.js new file mode 100644 index 000000000..430db6b8f --- /dev/null +++ b/test/validators/isMobilePhone.test.js @@ -0,0 +1,102 @@ +import test from '../testFunctions'; + +describe('isMobilePhone', () => { + describe('is Qatar phone number', () => { + it('should validate Qatar phone numbers', () => { + test({ + validator: 'isMobilePhone', + args: ['ar-QA'], + valid: [ + '+97435551234', + '+97455551234', + '+97465551234', + '+97475551234', + '35551234', + '55551234', + '65551234', + '75551234', + + ], + invalid: [ + '+97445551234', + '45551234', + '035551234', + '+97405551234', + '25551234', + '95551234', + '+9745555123', + '+974555512345', + '+9745555abcd', + '+97355551234', + '', + '+974', + ], + }); + }); + + it('should validate Qatar phone numbers in strict mode', () => { + test({ + validator: 'isMobilePhone', + args: ['ar-QA', { strictMode: true }], + valid: [ + '+97435551234', + '+97455551234', + '+97465551234', + '+97475551234', + '+974 55551234', + ], + invalid: [ + '+97445551234', + '35551234', + '55551234', + '035551234', + '+97405551234', + '+9745555123', + '+974555512345', + '+97355551234', + ], + }); + }); + + it('should validate when using multiple locales including Qatar', () => { + test({ + validator: 'isMobilePhone', + args: ['ar-QA'], + valid: [ + '+97435551234', + '+97455551234', + '35551234', + '55551234', + ], + invalid: [ + '+97445551234', + '+9125551234', + '25551234', + '+13005551234', + '+9745555123', + '', + ], + }); + }); + + it('should validate when using any locale', () => { + test({ + validator: 'isMobilePhone', + args: [], + valid: [ + '+97455551234', + '+13055551234', + '+447123456789', + '+61412345678', + ], + invalid: [ + '12345', + 'abc', + '', + '+9745555123', + '+97445551234', + ], + }); + }); + }); +}); From 59310d141cee6227d91708ef7c7e663282c6d2ec Mon Sep 17 00:00:00 2001 From: ward khaddour Date: Mon, 21 Apr 2025 20:58:24 +0300 Subject: [PATCH 2/2] resolve issues --- src/lib/isMobilePhone.js | 3 +- test/validators.test.js | 5 ++ test/validators/isMobilePhone.test.js | 102 -------------------------- 3 files changed, 6 insertions(+), 104 deletions(-) delete mode 100644 test/validators/isMobilePhone.test.js diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 5e0f4d869..b00391ea6 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -20,7 +20,7 @@ const phones = { 'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/, 'ar-TN': /^(\+?216)?[2459]\d{7}$/, 'az-AZ': /^(\+994|0)(10|5[015]|7[07]|99)\d{7}$/, - 'ar-QA': /^(\+?974\s?)?([3567]\d{3})(\s|-)?\d{4}$/, + 'ar-QA': /^(\+?974|0)?([3567]\d{7})$/, 'bs-BA': /^((((\+|00)3876)|06))((([0-3]|[5-6])\d{6})|(4\d{7}))$/, 'be-BY': /^(\+?375)?(24|25|29|33|44)\d{7}$/, 'bg-BG': /^(\+?359|0)?8[789]\d{7}$/, @@ -174,7 +174,6 @@ phones['zh-MO'] = phones['en-MO']; phones['ga-IE'] = phones['en-IE']; phones['fr-CH'] = phones['de-CH']; phones['it-CH'] = phones['fr-CH']; -phones['en-QA'] = phones['ar-QA']; export default function isMobilePhone(str, locale, options) { assertString(str); diff --git a/test/validators.test.js b/test/validators.test.js index 734a2a22b..718b9f58b 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -10688,6 +10688,11 @@ describe('Validators', () => { '80912345', ], }, + { + locale: 'ar-QA', + valid: ['+97435551234', '+97455551234', '+97465551234', '+97475551234', '35551234', '55551234', '65551234', '75551234'], + invalid: ['+97445551234', '+97405551234', '+9745555123', '+974555512345', '+97355551234', '+9125551234', '25551234', '+13005551234', '45551234', '95551234', '+9745555abcd', '', '+974'], + }, ]; let allValid = []; diff --git a/test/validators/isMobilePhone.test.js b/test/validators/isMobilePhone.test.js deleted file mode 100644 index 430db6b8f..000000000 --- a/test/validators/isMobilePhone.test.js +++ /dev/null @@ -1,102 +0,0 @@ -import test from '../testFunctions'; - -describe('isMobilePhone', () => { - describe('is Qatar phone number', () => { - it('should validate Qatar phone numbers', () => { - test({ - validator: 'isMobilePhone', - args: ['ar-QA'], - valid: [ - '+97435551234', - '+97455551234', - '+97465551234', - '+97475551234', - '35551234', - '55551234', - '65551234', - '75551234', - - ], - invalid: [ - '+97445551234', - '45551234', - '035551234', - '+97405551234', - '25551234', - '95551234', - '+9745555123', - '+974555512345', - '+9745555abcd', - '+97355551234', - '', - '+974', - ], - }); - }); - - it('should validate Qatar phone numbers in strict mode', () => { - test({ - validator: 'isMobilePhone', - args: ['ar-QA', { strictMode: true }], - valid: [ - '+97435551234', - '+97455551234', - '+97465551234', - '+97475551234', - '+974 55551234', - ], - invalid: [ - '+97445551234', - '35551234', - '55551234', - '035551234', - '+97405551234', - '+9745555123', - '+974555512345', - '+97355551234', - ], - }); - }); - - it('should validate when using multiple locales including Qatar', () => { - test({ - validator: 'isMobilePhone', - args: ['ar-QA'], - valid: [ - '+97435551234', - '+97455551234', - '35551234', - '55551234', - ], - invalid: [ - '+97445551234', - '+9125551234', - '25551234', - '+13005551234', - '+9745555123', - '', - ], - }); - }); - - it('should validate when using any locale', () => { - test({ - validator: 'isMobilePhone', - args: [], - valid: [ - '+97455551234', - '+13055551234', - '+447123456789', - '+61412345678', - ], - invalid: [ - '12345', - 'abc', - '', - '+9745555123', - '+97445551234', - ], - }); - }); - }); -});