admin管理员组文章数量:1322032
I would like to test if the right phone number was enterred in the text field. The phone number should be ddd-ddddddd which means 3digits then must have "-" and then 7 digits. How do I set the regular expression for that ? Thanks :)
I would like to test if the right phone number was enterred in the text field. The phone number should be ddd-ddddddd which means 3digits then must have "-" and then 7 digits. How do I set the regular expression for that ? Thanks :)
Share Improve this question asked Aug 2, 2011 at 20:30 Alon BAlon B 1554 silver badges13 bronze badges 4- 2 Exact duplicate of stackoverflow./questions/1736686/… – Lance Commented Aug 2, 2011 at 20:32
- I hate sites that require exact formats like that. It's so easy to scan through the digits alone and then add the dashes as necessary. /rant – Chris Gregg Commented Aug 2, 2011 at 20:34
- 1 The format asked for is not the same. – Alex Turpin Commented Aug 2, 2011 at 20:35
- I hate sites that require exact formats that only apply to one country. (Unless they make it really clear on the front page that they only deal with residents of that country, and even then - why?) /rant – nnnnnn Commented Aug 3, 2011 at 0:07
4 Answers
Reset to default 3/^\d{3}-\d{7}$/.test( phone_number );
var phoneNumber = '123-1234567';
if(phoneNumber.match(/^\d{3}-\d{7}$/))
{
alert('blah');
}
Exactly as you say it /^\d\d\d-\d\d\d\d\d\d\d$/
That's my take:
/^[0-9]{3}\-[0-9]{7}$/
本文标签: javascript regular expression phone number validationStack Overflow
版权声明:本文标题:javascript regular expression phone number validation - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742109593a2421182.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论