i want to validate check box by jquery validation adding rule and message. i did this way but some where i made the mistake for which code is not working.
i want user has to select one checkbox at least before form submit.
code
<form id="myform">
<input type="checkbox" name="test[]" class="clschk" />x
<input type="checkbox" name="test[]" class="clschk"/>y
<input type="checkbox" name="test[]" class="clschk"/>z
<input type="submit" />
</form>
<a id="docs" href="http://docs.jquery.com/Plugins/Validation" target="_blank">Validation Documentation</a>
js code
$(document).ready(function () {
$('#myform').validate({ // initialize the plugin
rules: {
'.clschk': {
required: true,
maxlength: 2
}
},
messages: {
'.clschk': {
required: "You must check at least 1 box",
maxlength: "Check no more than {0} boxes"
}
},
submitHandler: function (form) { // for demo
alert('valid form submitted'); // for demo
return false; // for demo
}
});
});