stefandoorn
stefandoorn

Reputation: 1032

jQuery Validate ignoring rules

This problem is holding me now for a while. It's probable an easy thing but at this hour I'm not seeing it. HTML & JavaScript is included below. jQuery 1.8.3 is loaded before jQuery validate and no JS errors are in there.

The problem is actually that even when submitting an empty value, the validator just accepts it as an accepted entry and submits the form (no errors in console).

HTML:

<form method="POST" id="reactieform">
<input type="hidden" name="reactie" value="1" />

<table style="float:left;">
    <tr>
        <td width="250">Voornaam</td>
        <td width="650"><input maxlength="150" type="text" name="voornaam" /></td>
        <td width="100"></td> 
    </tr>

    <tr>
        <td>&nbsp;</td>
        <td><input type="submit" value="Reactie opslaan" /></td>
    </tr>                   
</table>
</form>

JavaScript:

$(document).ready(function() {          
    $('#reactieform').validate({            
        voornaam: {
            required: true,
            minlength: 10
        }
    });
});

Upvotes: 0

Views: 1013

Answers (2)

Sparky
Sparky

Reputation: 98738

Your code is missing the rules option entirely. Your rules declaration must be placed inside the rules option.

$(document).ready(function() {          
    $('#reactieform').validate({    
        rules: {
            voornaam: {
                 required: true,
                 minlength: 10
            }
        }
    });
});

Working DEMO: http://jsfiddle.net/4kXuF/

Upvotes: 1

Adil Shaikh
Adil Shaikh

Reputation: 44740

Try this -

 rules:{
         voornaam: {
            required: true,
            minlength: 10
         }
       }

Upvotes: 2

Related Questions