views:

107

answers:

2

hi,

in my application i want to validate the telephone numbers, how can i write regular expression for telephone numbers like..

040-23357399 or 04023357399 91-40-23357399 or 914023357399 08518-2814655 or 085182814655 91-8518-2814655 or 9185182814655

this is my phone numbers how can i write the expression for this

+1  A: 

For more refer this

Another good link is this

Also check this regular expression:

^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$
HotTester
+2  A: 

Validation implies rejection, and your users will find that annoying. A better option is to accept as much as possible by first stripping all non-digits from the string, and then checking the length and initial digits vs a few simple rules:

  • If 11 digits and starts with a 1, strip first digit.
  • If 10 digits accept if it starts with 2-9.
  • If 12-14 digits accept if starts with a valid country code.
  • Rreject everything else.

This passes a lot more through than trying to force your users into a specific format, and makes for simpler, faster validation code. Then you just format it nicely whenever you re-display it.

Joel Coehoorn
Nice thought...But what if we want check it on the client side ?
HotTester
@HotTester Still strip non-digits and check via rules. You can write client-side javascript to go with a CustomValidator control in ASP.Net.
Joel Coehoorn