Skip to content

fix(isMobilePhone): restrict mk-MK locale to valid mobile numbers only #2579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const phones = {
'ar-YE': /^(((\+|00)9677|0?7)[0137]\d{7}|((\+|00)967|0)[1-7]\d{6})$/,
'ar-EH': /^(\+?212|0)[\s\-]?(5288|5289)[\s\-]?\d{5}$/,
'fa-AF': /^(\+93|0)?(2{1}[0-8]{1}|[3-5]{1}[0-4]{1})(\d{7})$/,
'mk-MK': /^(\+?389|0)?((?:2[2-9]\d{6}|(?:3[1-4]|4[2-8])\d{6}|500\d{5}|5[2-9]\d{6}|7[0-9][2-9]\d{5}|8[1-9]\d{6}|800\d{5}|8009\d{4}))$/,
'mk-MK': /^(\+3897[0-9]|07[0-9])[0-9]{6}$/,
Copy link
Preview

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern is too restrictive. It only matches numbers starting with +3897 or 07, but according to the test cases, +38971234567 should be valid. The pattern should be /^(+38970[0-9]|070[0-9])[0-9]{6}$/ or adjusted to match the actual mobile number format.

Suggested change
'mk-MK': /^(\+3897[0-9]|07[0-9])[0-9]{6}$/,
'mk-MK': /^(\+3897[1-9][0-9]{6}|07[1-9][0-9]{6})$/,

Copilot uses AI. Check for mistakes.

};
/* eslint-enable max-len */

Expand Down
41 changes: 13 additions & 28 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10551,6 +10551,19 @@ describe('Validators', () => {
'9603412345',
],
},
{
locale: 'mk-MK',
valid: [
'+38971234567',
'071234567',
],
invalid: [
'031234567',
'099999999',
'023456789',
'80001234',
],
},
{
locale: 'ar-YE',
valid: [
Expand Down Expand Up @@ -10660,34 +10673,6 @@ describe('Validators', () => {
'+50281234567',
],
},
{
locale: 'mk-MK',
valid: [
'+38923234567',
'38931234567',
'022123456',
'22234567',
'71234567',
'31234567',
'+38923091500',
'80091234',
'81123456',
'54123456',
],
invalid: [
'38912345678',
'+389123456789',
'21234567',
'123456789',
'+3891234567',
'700012345',
'510123456',
'This should fail',
'+389123456',
'389123456',
'80912345',
],
},
{
locale: 'ar-QA',
valid: ['+97435551234', '+97455551234', '+97465551234', '+97475551234', '35551234', '55551234', '65551234', '75551234'],
Expand Down