Tim Aych
Tim Aych

Reputation: 1365

jQuery validation plugin not validating my forms

I'm having trouble using the jQuery validation (http://jqueryvalidation.org/) plugin with one of my forms. I made a jsFiddle so that nobody has to see my ugly coded 9000 lined form:

http://jsfiddle.net/ndaMD/

source:

<form id="yeah">
First name: <input type="text" class="required" id="firstname" minlength=”4”><br>
Last name: <input type="text" name="lastname">
</form>

<a href="#" id="test123">HELLO</a>


$('#test123').click(function(){

    $( "#yeah" ).validate({
    });
});    

Can anyone tell me what's going wrong?

Upvotes: 0

Views: 70

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

You need to initialize the validator on dom ready and then on the click event call the valid() method to see whether the form is valid

jQuery(function ($) {
    $("#yeah").validate({});


    $('#test123').click(function () {
        if ($("#yeah").valid()) {
            console.log('do')
        }
    });
});

Demo: Fiddle

Upvotes: 1

Related Questions