From f9d49fc962816fc194a7f3e15ac1b2704e106bd9 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos <102623907+pano9000@users.noreply.github.com> Date: Sun, 29 Jan 2023 18:48:06 +0100 Subject: [PATCH] fix(isMobilePhone): fix 'ms-MY' regexp (#2155) refactored the regexp: --- * removed meaningless {1} quantifiers * simplified regexp a bit (removing useless escape character) * fixed the bug that would cause it to match invalid numbers tests --- * added tests for invalid numbers fixes #1066 --- src/lib/isMobilePhone.js | 2 +- test/validators.test.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index f2a385661..6906fdb2d 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -119,7 +119,7 @@ const phones = { 'mg-MG': /^((\+?261|0)(2|3)\d)?\d{7}$/, 'mn-MN': /^(\+|00|011)?976(77|81|88|91|94|95|96|99)\d{6}$/, 'my-MM': /^(\+?959|09|9)(2[5-7]|3[1-2]|4[0-5]|6[6-9]|7[5-9]|9[6-9])[0-9]{7}$/, - 'ms-MY': /^(\+?6?01){1}(([0145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/, + 'ms-MY': /^(\+?60|0)1(([0145](-|\s)?\d{7,8})|([236-9](-|\s)?\d{7}))$/, 'mz-MZ': /^(\+?258)?8[234567]\d{7}$/, 'nb-NO': /^(\+?47)?[49]\d{7}$/, 'ne-NP': /^(\+?977)?9[78]\d{8}$/, diff --git a/test/validators.test.js b/test/validators.test.js index b348d877e..8a7eacc84 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -8593,6 +8593,8 @@ describe('Validators', () => { '088-261987', '1800-88-8687', '088-320000', + '+01112353576', + '+0111419752', ], }, {