Click here to Skip to main content
15,906,708 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
How we can write one regular expression for both land line number and mobile number?
Posted
Comments
F-ES Sitecore 5-Jan-16 6:28am    
These kinds of tasks are bound to fail and do nothing but annoy your end user. You haven't even said what country you want this data for, it differs from country to country. What if someone wants to put their Guatemalan phone number in your Italian form? Personally I just wouldn't bother trying to validate the phone number format. If you really want to then contact the telecoms provider in your target region to determine what actually constitutes a valid number and go from there.

Depends on your number formats.
In the UK, mobile numbers start 071, 072, 073, 074, 075, 07624, 077, 078, and 079, with "Personal numbering" on 070, and Pagers on 076 (except 07624).
Non-mobile number start 01, 02, 03, 08, 09, with 04 reserved, 06 possibly going to be used for "Personal numbers", and 05 a bit confused.

So you could write a regex for that - but it wouldn't work in France, Italy, the USA, Indian, China, or a huge variety of other places where the numbering conventions may be different.

So start by looking at the numbering format for the country you are interested in, then get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900