Posted By

vagrantradio on 02/16/10


Tagged

regex email


Versions (?)

Who likes this?

7 people have marked this snippet as a favorite

mamona
alejandrosuch
jacinmontava
fenta23
jfherring
koyotebr
wattsupnow


CHECK VALID EMAIL ADDRESS JQUERY


 / Published in: jQuery
 

  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  

You need to login to post a comment.