I'm struggling to validate the value of an email input using this code. It's not working as expected and I could really use some assistance, please!
HTML
<input type="text" name="email" class="emailInput" />
<button class="validateEmail">VALIDATE</button>
JQUERY
$(document).ready(function(){
var userEmail = $(".emailInput").val();
var emailValidation = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
$(".validateEmail").click(function(){
if (emailValidation.test(userEmail)) {
alert("Email is valid!");
} else {
alert("Invalid email address.");
}
});
});