开发者

javascript regular expression phone number validation

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 ? T开发者_开发百科hanks :)


/^\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}$/
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜