12

I want to change the class that jQuery Validate applies to inputs that have an error

Change this

<input id="firstname" name="firstname" type="text" value="" maxlength="100"
class="error">

to this

<input id="firstname" name="firstname" type="text" value="" maxlength="100" 
class="customErrorClass">

2 Answers 2

33

Try specifying the errorClass property:

$('.selector').validate({
    errorClass: 'customErrorClass',
    rules: { ... },
    messages: { ... }
});
Sign up to request clarification or add additional context in comments.

3 Comments

Works like a champ, thanks. That is NOT on this page.
@guanome, no, but it is on this one.
The old documentation links above no longer work. Here is an updated link for 2021: jqueryvalidation.org/validate/#errorclass
0

The one can use code as following for Custom Css

<style>
  .myErrorCssClass {
    border: solid 1px #ff0000;
  }
</style>

<script>
  $('#form1').validate({
    errorClass: "myErrorCssClass",
    rules: {
      Name: {
        required: true,
        minlength: 3,
        maxlength: 10
      },
      LastName: {
        required: true
      }
    }
  })
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.