简体   繁体   中英

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
        }
    });
});

Try this -

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

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM