开发者

javascript regular expression phone number validation

开发者 https://www.devze.com 2023-03-25 00:04 出处:网络
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.

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

精彩评论

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