Can someone rewrite this javascript. The problem now is that 1 regex is only working( that one from email)
earlier question: link
I got advice here but I think I put it not good in my code
function checkform ( form )
{
var rex = /[^a-z]/i;
var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!regex.test(form.email.value))
{
alert( "Please enter youre valid email address." );
form.email.focus();
return false ;
}
if (rex.test(form.name.value))
{
alert( "Please enter your name. no numbers or #$^& things allowed)." );
form.name.focus();
return false ;
}
return true ;
}
Assuming you want the two form fields to behave the same way, the first one is being tested for negative.
You said the email one works, so perhaps you meant to write
if ( ! rex.test(for.name.value) )