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}$/
精彩评论