Search code examples
javascriptjqueryhtmljquery-validate

JQuery validation plugin maxlength?


I am using JQuery validation plugin. I want to specify maxlength for one of the fields.It can be specified as below.

rules: {
   Message: {
      required: false,
      maxLength: 200
   }
}

But instead of defining the rules externally, i want to specify the rules inside html input code

Similar to :

<input type="text" name="AssistanPhone" value="" class="required"  />

In above example "required" is specified through class. Similarly how can i specifiy maxlength which can be recognized by jquery plugin and gives error message if length exceeds?

Thanks!


Solution

  • Not capital L its l

    Ex:

    $( "#myform" ).validate({
      rules: {
        field: {
          required: true,
          maxlength: 200
        }
      }
    });
    

    PLUGIN DEMO