Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 674
user755806 Avatar asked Dec 25 '22 22:12

user755806


2 Answers

Not capital L its l

Ex:

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

PLUGIN DEMO

like image 152
Suresh Atta Avatar answered Dec 28 '22 12:12

Suresh Atta


As far as I can see you cannot specify the messages via attributes, but the maxlength can be specified as a attribute

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

Demo: Fiddle

like image 43
Arun P Johny Avatar answered Dec 28 '22 12:12

Arun P Johny