validatorjs / validator.js

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

mobile phone vs non-mobile phone #433

Closed ORESoftware closed 9 years ago

ORESoftware commented 9 years ago

I didn't see any clarification as to if the mobile phone number validator checks to see if a phone number is a mobile phone number and not a landline or if it just eliminates 800 numbers, etc.

I did check and it doesn't accept (800)555-0101 numbers, but does it accept any other landline numbers?

How does it differentiate? It can't possibly differentiate between landline numbers and mobile numbers without using a database, right?

Explanation desired, thanks!

chriso commented 9 years ago

Phone number validation is tough (see how big this repo is: https://github.com/googlei18n/libphonenumber), but mobile phones tend to be easier to validate and so it's here in the library ;)

chriso commented 9 years ago

You can see the patterns in use here: https://github.com/chriso/validator.js/blob/b20a8db53b112eea86dfed9b9d6efabb4cde63de/validator.js#L82-L93

chriso commented 9 years ago

Do give you an example, all mobile phone numbers in Australia start with 04 and can be validated with /^04\d{8}$/ locally, or /^+?614\d{8}$/ for international versions of the same numbers. Landlines start with 02, 03, 05 and 07 (and probably others) depending on the state and have additional rules in place for each region. I'm not familiar with the rules of other countries and so have relied on pull requests to add locales.