I am using jQuery Validate plugin for the validation purpose. I have to real time validation on the form. For example if a first name is required, then user
You would never use the .valid()
method within the .validate()
method. Refer to the source code of onkeyup
and onfocusout
to see how it's done.
Use this.element(element)
instead of $(element).valid()
To over-ride the default functionality ("lazy validation") of onkeyup
and onfocusout
and use "eager" validation instead...
$('#myform').validate({
onkeyup: function(element) {
this.element(element); // <- "eager validation"
},
onfocusout: function(element) {
this.element(element); // <- "eager validation"
}
....
DEMO: http://jsfiddle.net/ajy5j8jq/