开发者

jQuery Validate property 'max' isn't working on my input field

I have an input that I want to set the max value to 255. I'm not submitting the form, but rather calling a function which submits the data via ajax.

Some of the other validate checks are working, like required and digits, but max isn't working. I'm using jQuery 1.4.4 and validate 1.7.

HTML

<input type="text" maxlength="3" style=" width: 190px" value="" name="Repeats" id="formfield_Repeats">

JavaScript

$(document).ready(function () {
   $("#my_form").validate({
      rules: {
         formfield_Repeats: {
            digits: true,
            required: true,
            max: 255
         }
      }
   });
});

When I go to save the app I call the valid() method on the form.

Is it a version mismatch with jQuery and the validate plugin? I could upgrade both, but the project is HUGE and I don't necessarily want to have to retest the entire 开发者_运维百科app.


jquery validate uses the NAMES of inputs, not the id's so you should have:

$(document).ready(function () {
   $("#my_form").validate({
      rules: {
         Repeats: {
            digits: true,
            required: true,
            max: 255
         }
      }
   });
});

EDIT: hmm, ok, let's try adding the rule directly to the input field:

$("#my_form").validate();

$('#formfield_Repeats').rules('add', {
    required: true,
    digits: true,
    max: 255
});

EDIT: have a look at this js fiddle: it shows this working exactly as expected with validate 1.7 and jquery 1.4.4 http://jsfiddle.net/Et9vM/


hi it should maxlength instead of max... Just go through this Link for maxlength validation jquery

Hop this helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜