Validations is working fine, if valid email is entered, displays a hidden box if not valid is showing a message error on a overlay, but how to check if keydown or return? any ideas guys?
This is my code, which can also be accessed in a jsFiddle:
function validateEmail() {
var validEmail = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
$('#user_email').blur(function(){
if (validEmail.test(this.value)) {
$('.masked-check').fadeIn(300)
}
else {
$('.masked-check').fadeOut(300);
$('.overlay').append('<div class="alert alert-error" id="errors"></div>');
showOverlay($('#errors').html('Please enter a valid email...'));
}
});
}
validateEmail();
I not sure if this is the way to do it but works for me now, the only issue is not listening to a keypress keyup or keydown. Here is the updated http://jsfiddle.net/creativestudio/bKT9W/3/ I am not sure is this is the best way to do it but works for now.
function validateEmail() {
var validEmail = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
$('#user_email').blur(function(){
$('.masked-check').hide();
if (validEmail.test(this.value)) {
$('.masked-check').fadeIn(300)
}
else {
$('.masked-check').fadeOut(300);
$('.overlay').append('<div class="alert alert-error" id="errors"></div>');
showOverlay($('#errors').html('Please enter a valid email...'));
}
if ($('#user_email').val()=='') {
$('.masked-check').hide()
}
});
}
validateEmail();