JQuery Email Field Validation


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

Used to automatically give feedback on email address validity.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.