Click here to Skip to main content
12,406,528 members (30,083 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
how we validate phone num in dottnet
Posted 16-May-11 10:32am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
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.
d@nish 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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Use a RegularExpressionValidator
Tutorial:
http://www.w3schools.com/ASPNET/control_regularexpvalidator.asp[^]
  Permalink  
Comments
Abhinav S 17-May-11 5:44am
   
Good answer. 5.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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[^]
  Permalink  
Comments
Abhinav S 17-May-11 5:44am
   
Good link. 5.
Marcus Kramer 17-May-11 7:58am
   
Thanks.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

try Regular Expresion validation

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
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
  Permalink  
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!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

Hope this[^] also might help you.
  Permalink  
Comments
Abhinav S 17-May-11 5:45am
   
My 5.
Ramalinga Koushik 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160730.1 | Last Updated 17 May 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100