lady_OC
lady_OC

Reputation: 417

Call JQuery Validate Plugin without submitting the form

Is it possible to validate the form without submitting it using the JQuery validation plugin?

I use a button.click function for validating, the button isn't a submit input.

Upvotes: 10

Views: 38189

Answers (1)

Sparky
Sparky

Reputation: 98718

Yes, it is possible to test the form's validity without submitting it.

See .valid() method.

Whenever .valid() is called the form is tested, and the method will also return a boolean.

$(document).ready(function () {

    $('#myform').validate({ // initialize the plugin
        // rules & options
    });

    $('#button').click(function() {
        if ($('#myform').valid()) {
            alert('form is valid - not submitted');
        } else {
            alert('form is not valid');
        }
    });

});

Working DEMO: http://jsfiddle.net/zMYVq/

Upvotes: 32

Related Questions