0

my code: http://jsfiddle.net/umSFC/

i follow How to validate email in Jquery? for email validation but seem dont work on mine?

Community
  • 1
  • 1
tonoslfx
  • 3,342
  • 15
  • 64
  • 105

2 Answers2

0

Use jQuery Validate plugin. Has an email validator for what you want and is better to use a consistent validation throughout your application and forms. On other hand is better to use tested components and whenever possible use existing works and not reinvent the wheel.

Elzo Valugi
  • 25,880
  • 14
  • 91
  • 114
  • I agree http://stackoverflow.com/questions/1229259/jquery-pitfalls-to-avoid/1238258#1238258, but as you can see validate is an exception. – Elzo Valugi Feb 17 '11 at 09:13
0

Here i have fixed your exsample

$(document).ready(function() {

    $("#submit").click(function(e) {

        var name = $("#name");
        var email = $("#email");
        var emailaddressVal = $("#email").val();
        var emailReg = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i;


        if (name.val() == "") {
            name.addClass("error").focus();
            return false;
        } else {
            name.removeClass("error");
        }

        if (!emailReg.test(email.val())) {
            email.addClass("error").focus();

        } else {

            email.removeClass("error");
        }



        e.preventDefault();
    });

});
Kimtho6
  • 6,024
  • 9
  • 39
  • 56