Skip to content Skip to sidebar Skip to footer

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

Solution 1:

/^\d{3}-\d{7}$/.test( phone_number );

Solution 2:

var phoneNumber = '123-1234567';
if(phoneNumber.match(/^\d{3}-\d{7}$/))
{
   alert('blah');
}

Solution 3:

Exactly as you say it /^\d\d\d-\d\d\d\d\d\d\d$/

Solution 4:

That's my take:

/^[0-9]{3}\-[0-9]{7}$/

Post a Comment for "Javascript Regular Expression Phone Number Validation"