I am using jquery and jquery.validate.cs (jQuery Validation Plugin 1.8.0) to validate a form. Right now it displays a message next to a field saying : "This is a required field".
I also want each field to turn red color. How would i do that? Thanks!
Then to define rules use simple syntax. jQuery(document). ready(function() { jQuery("#forms). validate({ rules: { firstname: 'required', lastname: 'required', u_email: { required: true, email: true,//add an email rule that will ensure the value entered is valid email id.
According to the jQuery validate documentation for remote: The response is evaluated as JSON and must be true for valid elements, and can be any false, undefined or null for invalid elements, using the default message; or a string, eg. "That name is already taken, try peter123 instead" to display as the error message.
Without any custom configuration, you can just do this:
select.error, textarea.error, input.error {
color:#FF0000;
}
error
valid
.These classes are also applied to the error label, so be aware of that when writing your CSS.
The validation plugin allows you to configure these class names, so you may do something like this:
$("form").validate({
errorClass: "my-error-class",
validClass: "my-valid-class"
});
.my-error-class {
color:#FF0000; /* red */
}
.my-valid-class {
color:#00CC00; /* green */
}
The configuration options can be found at http://docs.jquery.com/Plugins/Validation/validate
$("#myform").validate({
error: function(label) {
$(this).addClass("error");
},
});
use the errorClass parameter to add the .invalid class:
input.error {
color: red;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With