开发者

problem with max in jquery.validate plugin

I have the code that you can check in this fiddle: http://jsfiddle.net/4SCrp/5/

<form id="my_form">
    <input id="formfield1" type="text" maxlength="3" value="">
    <br/>
    <input id="formfield2" type="text" maxlength="3" value="">
    <br/>
    <input type="submit" value="submit">
</form>

and th followin script using jquery.validate plugin

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

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

$('#formfield2').rules('add', {
    required: true,
    digi开发者_Python百科ts: true,
    max: 2
});

It is supposed to acept a maximum of 255 in the first field and a maximum of 2 in the second. But both give the error "Please enter a value less than or equal to 2." so it takes for all the last max defined.

Do you know how to solve that problem?


Its maxlength you need - not max check here -> http://docs.jquery.com/Plugins/Validation/Methods/maxlength#length

Try specifying the rules as follows :

$("#my_form").validate({
    rules: {
        formfield1: {
            required: true,
            digits: true,
            max: 255
        },
        formfield2: {
            required: true,
            digits: true,
            max: 2
        }
    }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜