The jQuery Validation plugin works great and is very easy to use:
$(\".selector\").validate({
})
Just by setting css classes like \"require
$.validator.addMethod("cMaxlength", function(value, element, param) {
return $.validator.methods.maxlength.call(this, value, element, param[1]);
}, '{0}');
$.validator.addMethod("cMaxlength", function(value, element, param) {
return $.validator.methods.maxlength.call(this, value, element, param[1]);
}, '{0}');
Before this you have to include Query file
$("#myform_name").validate({
onfocusout: function(element) { $(element).valid(); } ,
rules:{
myfield_name: {
required:true
},
onkeyup: false,
messages: {
myoffer: "May not be empty"
}
}
});