How to Validate Email address in Jquery
Hello,
I have the following code that helps to check if email is already in database or not. I want to be able to validate email address in the jquery so when someone enters just the name it does not validate the email address unless all of the email address has been tyoed up. My code is: $(document).ready(function() { //On Change $("#email").change(function() { var email = $("#email").val(); var msgbox = $("#emailstatus"); $("#emailstatus").html('<img src="images/loader.gif" align="absmiddle"> Checking availability...'); $.ajax({ type: "POST", url: "mod/email.php", data: "email="+ email, success: function(msg){ $("#emailstatus").ajaxComplete(function(event, request){ if(msg == 'OK') { $("#email").removeClass("userred"); $("#email").addClass("usergreen"); msgbox.html('<img src="images/yes.png" align="absmiddle"> <font color="Green"> Available </font> '); } else { $("#email").removeClass("usergreen"); $("#email").addClass("userred"); msgbox.html(msg); } }); } }); return false; }); }); I just need to know how in this code I can check to make sure email is being validated before it is being accepted. Thank you
2 Answers
Thanks for the reply. I could find loads of email validations for jQuery but I could not get it to work inside the code I have.
I need a solution that will work with my code.. Where could I put it in the jQuery code I have that it will work. Thanks Posted: qakbar 0 of 0 people found this answer helpful. Did you? Yes No function isValidEmailAddress(emailAddress) { var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i); return pattern.test(emailAddress); }; Posted: molhm 1 of 1 people found this answer helpful. Did you? Yes No |
© Advanced Web Core. All rights reserved