Rahul Desai
Rahul Desai

Reputation: 15501

jQuery validate onfocusout

I am trying to validate this form located here: http://jsfiddle.net/PEmFH/8/ I want to validate on onfocusout (validate every time the user leaves the field). It is not working for some reason.

Please find the updated fiddle here: http://jsfiddle.net/PEmFH/11/

Upvotes: 1

Views: 11587

Answers (2)

Anil Singh
Anil Singh

Reputation: 4212

It might help too

//This is used to validate the Length Exceeded to Account number text box.
    $('#AccountName').focusout(function () {
        var currentVal = $.trim($('#AccountName').val()).toLocaleLowerCase().length;
        if (currentVal > 50) {
            alert("Length Exceeded");
            return false;
        }
    });

Upvotes: 0

Nicolás Apolonia
Nicolás Apolonia

Reputation: 91

You should use the "element" method that returns true or false if a element is valid or not http://jqueryvalidation.org/Validator.element/

This is the way i solved:

$.each($('#form input[type="text"], #form textarea'), function(index, control) {
    $(control).focusout(function() {
        if ($('#form').validate().element(this)) {
           //Code for show a valid message or remove a invalid message                     
        } else {
           //Code for show a invalid message
        }
    });                
});

Upvotes: 1

Related Questions