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,422
  • 15
  • 65
  • 107
  • http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html <-- here's a very concise RegExp you could use...? :P – Dan Beam Feb 17 '11 at 09:32

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
  • 27,240
  • 15
  • 95
  • 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,154
  • 9
  • 40
  • 56