This is my email address validation code using JavaScript. The alert messages are correctly working but when I submit giving a valid email address it alerts 'Please provide a valid email address'. Please help me.
if(email=="")
{
alert("Enter emailid");
$("#email").focus();
return false;
}
else if(email!="")
{
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value))
{
//alert(email)
//alert(filter.test(email.value))
alert('Please provide a valid email address');
email.focus();
return false;
}
}