Phone number validation using JS


if (txtPhone.value == '')
{
   alert("Please enter phone number.");
   txtPhone.focus();
   txtPhone.value='';
   txtPhone.style.border = '1px solid red';
   return false;
}
else if (txtPhone.value != "")
{
   var targ=txtPhone.value.replace(/[^\d]/g,''); // remove all non-digits
   if(!targ || isNaN(targ) || targ.length!=10)
    {
        alert("Invalid Phone number.");
        txtPhone.value = "";
        txtPhone.style.border = '1px solid red';
        txtPhone.focus();
        return false;
    }
}

Comments