function validate_email() {
atsplit = $('input[name=email]').val().split('@');
dotsplit = atsplit[1].split('.');
if (atsplit.length == 2 && atsplit[0].length > 0 && dotsplit[dotsplit.length-1].length > 0 && dotsplit[dotsplit.length-2].length > 0) {
$('#email').html('✔');
valid_email = true;
}
else {
$('#email').html('');
valid_email = false;
}
}
$('*').live('change click focusout keyup submit', function(){
validate_email();
});
I’m trying to validate an email address. If the email is valid, a check mark is placed in the #email span. Everything works perfectly unless you highlight the input text and press the backspace key (or if you hold the backspace key so that the input is deleted in one keystroke). In these cases, the check mark remains regardless of what events are triggered (click, focusout, etc.). The behavior seems to be the same in all browsers. Any ideas what’s wrong?
Try out this http://jsfiddle.net/Pq5Ut/ and let me know if that helps you out. I know I’m not using the same email validation that you are, but I feel it might be what you want.
FYI, the email regex I’m using was just pulled from the jQuery validation plugin.