Posted By

boondoklife on 08/04/12


Tagged

email jquery validation


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

BrockSamsom


JQuery Email Field Validation


 / Published in: jQuery
 

Used to automatically give feedback on email address validity.

  1. (function ($) {
  2. $.fn.validateEmail = function () {
  3. return this.each(function () {
  4. var $this = $(this);
  5. $this.change(function () {
  6. var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  7. if ($this.val() == "") {
  8. $this.removeClass("badEmail").removeClass("goodEmail")
  9. }else if(reg.test($this.val()) == false) {
  10. $this.removeClass("goodEmail");
  11. $this.addClass("badEmail");
  12. }else{
  13. $this.removeClass("badEmail");
  14. $this.addClass("goodEmail");
  15. }
  16. });
  17. });
  18. };
  19. })(jQuery);

Report this snippet  

You need to login to post a comment.