Im trying to make some validation with javascript for a phone number field of a form.
I have taken some RegEx from another website and it almost works.
But the javascript does allow the form to submit if you place letters inbetween numbers like so "1234abc5678"
here is my validation code:
if (telephone==null || telephone=="")
{
alert("Telephone must be filled out");
return false;
}
var regexp = telephone.replace(/^[\s()+-]*([0-9][\s()+-]*){6,20}$/);
if (telephone.match(regexp))
{
alert("Telephone number is not valid");
return false;
}
Could someone help me with this code and tell me what is going wrong
After 1 more test I found that it allows letters within the numbers if I add a + at the beginning. I do need to allow the + at the start but obviously not the letters.
My required output would be for a phone number between 6 and 20 characters in length, which also allows a + at the start if one should be entered. any other characters should be invalid