Link to home
Start Free TrialLog in
Avatar of chadaort
chadaort

asked on

Javascript phone number validation

I am trying to validate a phone number using javascript.  The piece of code below checks for the format but it will allow you to exceed 4 characters at the end.  How do I stop that, I thought about using HTML and not allowing anymore characters but what would be the way with javascript?


function FormValidate()
{
   if(document.ChronoContact_clientForm.SocNumber.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1)
   {
      alert("The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
      return false;
   }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of third
third
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial