The following HTML form successfully utilizes jQuery\'s form validation, displaying \"This field is required\" to the right of the form field if left blank, and \"Please ent
$("#commentForm").validate({
rules: {
cname : { required : true, minlength: 2 }
}
});
Should be something like that, I've just typed this up in the editor here so might be a syntax error or two, but you should be able to follow the pattern and the documentation
rules: {
cname: {
required: true,
minlength: 2
}
},
messages: {
cname: {
required: "<li>Please enter a name.</li>",
minlength: "<li>Your name is not long enough.</li>"
}
}
The input in the markup is missing "type"
, the input (text I assume) has the attribute name="name"
and ID="cname"
, the provided code by Ayo calls the input named "cname"* where it should be "name".
The examples contained in this blog post do the trick.