I apologize in advance - this should be something really simple and for some reason I can't get it to work correctly (I'm new to javascript!). I'm trying to do some client-side javascript validation (I will also server-side validation) but it doesn't work as hoped!
I know about Validate email address in Javascript? but for some reason, I can't get it to work in my code. Here is the if statement (it's part of a couple of things that happen on a button press):
var signUpEmail = document.getElementById('signUpEmail');
var emailVerification = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
//Validates email address
if (emailVerification.test(signUpEmail) == false) {
alert("Please enter a valid email address");
return false;
};
Every time I press the button with anything (even a correct email) in the field, the alert displays.