validatorjs / validator.js

String validation
MIT License
23.01k stars 2.29k forks source link

Incorrect regex pattern #2312

Closed amir-khoshbakht closed 4 weeks ago

amir-khoshbakht commented 11 months ago

https://github.com/validatorjs/validator.js/blob/b958bd7d1026a434ad3bf90064d3dcb8b775f1a9/src/lib/isMobilePhone.js#L95C26-L95C26

I think this part of this pattern is wrong: image

this regex pattern matches : '90', '91', '92', '93', and '99'. While in reality it can be any number after the number 9. according to this wikipedia page the actual pattern for mobile number in this region is: 09xx xxx xxxx. so the 094...... is a valid number for this region while this regex code does not include it.

codevivekk commented 11 months ago

HI I would like to work on this issue

codevivekk commented 11 months ago

Hi i have raised the pr please check https://github.com/validatorjs/validator.js/pull/2316

pano9000 commented 11 months ago

Hi,

thanks for your comment. If I check the official ITU numbering plan for Iranian mobile number, the current Regex is too permissive already, and your proposed change would be even more permissive

https://www.itu.int/dms_pub/itu-t/oth/02/02/T02020000660028PDFE.pdf

saikiran76 commented 11 months ago

'fa-IR': /^(\+?98|0)?9\d{9}$/, This updated pattern allows for any digit after '9' and ensures that the phone number starts with '09' and is followed by 9 digits. With this change, the regex pattern will correctly match Iranian mobile phone numbers in the "09xx xxx xxxx" format.

pano9000 commented 4 weeks ago

kindly reference my comment above: we need to be more restrictive, not permissive with the rule - at least if we want to stick to the "official" document

WIkipedia is not a proper reference, and I haven't received any other references, so I'll go ahead and close this one