Click here to Skip to main content
14,920,488 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
how we validate phone num in dottnet
Posted

You can use from the ASP.Net Validators available. You can make use of RegularExpression validator or may be custom validator for this purpose.

Also take a look at MaskedTextBox from the AjaxToolkit if that suits you.
   
Comments
waqasahmed786 16-May-11 16:40pm
   
can u plz gave me the code of regular expression plz so that i can paste it in re validators
yesotaso 16-May-11 17:38pm
   
Dont get me wrong, dealing with regex is messy work. You should get a 3rd party help like "http://www.ultrapico.com/Expresso.htm".
Sample from Expresso: \((?<AreaCode>\d{3})\)\s*(?<number>\d{3}(?:-|\s*)\d{4}) which matches (555) 555-5555.
lw@zi 16-May-11 17:43pm
   
It depends on the format of the phone numbers you want to allow. Try RegExLib for examples.
Abhinav S 17-May-11 5:45am
   
Good options. 5.
Use a RegularExpressionValidator
Tutorial:
http://www.w3schools.com/ASPNET/control_regularexpvalidator.asp[^]
   
Comments
Abhinav S 17-May-11 5:44am
   
Good answer. 5.
Try reading this article found here on CP. It gives a really good explanation of the reg ex process and can be directly applied to your question.
Validation with Regular Expressions Made Simple[^]
   
Comments
Abhinav S 17-May-11 5:44am
   
Good link. 5.
fjdiewornncalwe 17-May-11 7:58am
   
Thanks.
try Regular Expresion validation

C#
f.e.:+420 333 222 111

Pattern: /^(\+[0-9]{0,3})*( ([0-9]{0,3})){3}$/

Finds U.S. phone numbers with extensions.
Pattern: /(\+?1[-\.\/ ])?(\(?\d{3}\)?[ \.\-\/]?)?(\d{3})[\-\.\/ ]([\d]{4}|[A-Z]{7})(\(\d{4}\))?(( )?(ext\.)|(x\.?)? ?\d{4})?(([ ,\/] ?\d{4})?)+/g

morocco phone number like this one :+21260010101or 0021260010101the code will find the both number it's my first code here :))
Pattern: (\+|00)(212)\d{8}

Phone Number   Extension (allows (), ., -, and space)

/^\(?([0-9]{3})\)?\s*[\. -]?\s*([0-9]{3})\s*[\. -]?\s*([0-9]{4})\s?((ext|x)\s*\.?:?\s*([0-9]+))?$/i

C#
Phone number india
^([+][9][1]|[9][1]|[0]){0,1}([7-9]{1})([0-9]{9})$

Pattern: /^[0-9]{0,5}[ ]{0,1}[0-9]{0,6}$/g
   
v4
Comments
Abhinav S 17-May-11 5:44am
   
Good approach. 5.
ambarishtv 17-May-11 5:46am
   
thank you abhinav :)
Gaurav Agarwal from Jaipur 13-Jun-13 6:04am
   
thanks man!
Hope this[^] also might help you.
   
Comments
Abhinav S 17-May-11 5:45am
   
My 5.
[no name] 17-May-11 5:52am
   
Thanks Abhinav

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