Dominic Francis
Dominic Francis

Reputation: 419

real time form validation using jQuery

I would like to create a form that validates each field if the user looses focus on a field.

So for example, a user may focus on the username field, not fill anything in and then tab out.

I've come across this jQuery plugin http://jqueryvalidation.org/

However it only seems to work when a user clicks the submit button.

Has anyone manipulated it so that it will do it will validate the form before the submit button is pressed?

Many Thanks

Upvotes: 0

Views: 1917

Answers (1)

Tricky12
Tricky12

Reputation: 6820

There might be a better way to do this, but you can use the .valid() function on blur to trigger validation on your inputs when the user exits the field.

$('input').on('blur', function() {
    $(this).valid();
});

.valid()

Note: You will need to call .validate() on your form before you can use the valid() function, which you should be doing already if it works on submit.

Upvotes: 1

Related Questions