最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

regex - Mobile or phone number validation in javascript - Stack Overflow

programmeradmin2浏览0评论

I need to validate phone or mobile number in javascript.
It should match the following types:
+91-9198387083
9198387083
09198387083
It is a 10 digit number with one of these four prefixes '+91-', '+91', '0' or ''
Can someone suggest me a regex expression in javascript which matches all the three types.

I need to validate phone or mobile number in javascript.
It should match the following types:
+91-9198387083
9198387083
09198387083
It is a 10 digit number with one of these four prefixes '+91-', '+91', '0' or ''
Can someone suggest me a regex expression in javascript which matches all the three types.

Share Improve this question edited Dec 26, 2011 at 17:07 Devashish Dixit asked Dec 26, 2011 at 16:58 Devashish DixitDevashish Dixit 1,1936 gold badges16 silver badges25 bronze badges 1
  • possible duplicates: stackoverflow./questions/2386054, stackoverflow./questions/5286046 – Bergi Commented Dec 26, 2011 at 17:06
Add a ment  | 

4 Answers 4

Reset to default 10

I'd using something like this:

/^(\+91-|\+91|0)?\d{10}$/

This is very specific about one of your three allowable prefixes (or no prefix) followed by exactly 10 digits and no extra characters on the beginning of end of the string.

Test app with both valid and invalid phone numbers here: http://jsfiddle/jfriend00/K9bjL/

Something like this should work:

/\+?[0-9]+-?[0-9]/

10 digit number with one of these four prefixes +91-, +91, 0 or :

/(\+91-?|0)?\d{10}/
+7 (123) 45-67-890
8(123)381-198-2
and etc.

My simply mask for all of similar phones

/^[+]?(\d[^\d]*){11}$/
发布评论

评论列表(0)

  1. 暂无评论