开发者

validation on telephone numbers?

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开发者_JS百科 my phone numbers how can i write the expression for this


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.


For more refer this

Another good link is this

Also check this regular expression:

^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜