CHECK VALID EMAIL ADDRESS JQUERY


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $(function(){
  2.  
  3. var email = $("input#email").val();
  4. if(isValidEmailAddress(email)) {
  5. $(email).after("hooray!");
  6. } else {
  7. $(email).addClass("yourerror").after("<label class='error'>Email is not valid!</label>").focus();
  8. return false;
  9. }
  10. });
  11.  
  12. function isValidEmailAddress(emailAddress) {
  13. var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
  14. return pattern.test(emailAddress);
  15. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.