validatorjs / validator.js

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

Feature Request: isMobilePhone refactoring #934

Open tux-tn opened 5 years ago

tux-tn commented 5 years ago

Hello,

The logic behind isMobilePhone is to provide a regex for every locale, but i can see that that there is many issues related to generic and too permissive regex. I can mention #917, #919 and #921 as examples and there is even more invalid validation rules:

And i think we can provide more examples with some research

That's why i'm suggesting we refactor isMobilePhone using Google's libphonenumber as a fully functional alternative. The project is under Apache 2.0 licence and provides a Javascript library.

Waiting for your feedbacks

fkm commented 5 years ago

I don't know what the performance and size of libphonenumber is but I like the idea of outsourcing this rather complex validation to Google's package :-)

tux-tn commented 5 years ago

@chriso @profnandaa any feedback?

profnandaa commented 5 years ago

I'm good with it as long as it's going to be mostly opaque to the end user (+ be backward compatible). I don't know what @chriso thinks?

chriso commented 5 years ago

It's my understanding that libphonenumber is huge so not something we'd look to incorporate into the library. I'd rather remove isMobilePhone entirely and let the user decide whether the large footprint of libphonenumber is worth it for their app.

zoxon commented 3 years ago

Why isMobilePhone validator is used language codes instead of country codes?

profnandaa commented 3 years ago

Ideally it should be country codes but for backward compatibility, we continued with the initial approach.