Again JQuery has improved and simplified from the process outlined earlier in this blog
for form validation just add jquery.validate plugin and then in the code add:-
$("#commentForm").validate();or more likely you’ll have a more complex form so you’ll need to specify a few attributes
var validator = $("#health").validate({
rules: {
radiofield: "required",
textfield: "required",
email: {required: true,email: true},
name: "required"
},
messages: {
email: {
required: "Please enter a valid email address",
minlength: "Please enter a valid email address",
},
radiofield: "Please Select The number of items to Check"
},
// the errorPlacement has to take the table layout into account
errorPlacement: function(error, element) {
if ( element.is(":radio") )
error.appendTo( element.parent() );
else if ( element.is(":checkbox") )
error.appendTo ( element.next() );
else
error.appendTo( element.parent() );
},
})For the full documentation go to http://docs.jquery.com/Plugins/Validation
And don’t forget to handle the form with javascript disabled!
Tags: field validation, form, form checking, javascript, JQuery, validation