Closed cybertk closed 10 years ago
There are already some stable libs for this purpose, such as Google's libphonenumber
On Sat, Aug 30, 2014 at 6:20 PM, Morgan Cheng notifications@github.com wrote:
I suppose this is hard, since different country and region has different length of phone number.
— Reply to this email directly or view it on GitHub https://github.com/chriso/validator.js/issues/310#issuecomment-53954613.
This has been brought before in #99, #167 and #263. Each time I've rejected it as phone numbers vary considerably depending on where you are in the world.
@chriso, ITU has defined a spec to describe the format of a international phone number. And Google has a implementation named libphonenumber of this spec, libphonenumber is used by all Android devices around the world.
There is also a javascript porting for libphonenumber.
So it's possible to provide a API to validate international phone number. i.e. validator.isPhoneNumber('+86 (0) 25 8956-2842')
I think that would be a great thing to support such spec, especially since it is used b google for smartphones in many countries. Phone number are complicated, as you said and having a support for it like that would help a lot.
libphonenumber is huge. It requires Google's Closure library and if you look at the implementation it looks to be >0.5MB, or put another way: 50x larger than the entire validator.js library. There's no point duplicating it. If you need phone validation then use libphonenumber directly. If you need something more lightweight or locale-specific, use regular expressions.
Then you should explain this on the README to avoid to get requests for phone numbers features.
2014-09-07 6:59 GMT+02:00 chriso notifications@github.com:
libphonenumber is huge. It requires Google's Closure library and if you look at the implementation https://github.com/mattbornski/libphonenumber/tree/master/lib/closure/goog/i18n/phonenumbers it looks to be >0.5MB, or put another way: 50x larger than the entire validator.js library. There's no point duplicating it. If you need phone validation then use libphonenumber directly. If you need something more lightweight or locale-specific, use regular expressions.
— Reply to this email directly or view it on GitHub https://github.com/chriso/validator.js/issues/310#issuecomment-54737456.
Cordialement,
M. Ambroise Dhenain.
I suppose this is hard, since different country and region has different length of phone number.