开发者

Problem using rangelength for jQuery validation

开发者 https://www.devze.com 2022-12-16 13:31 出处:网络
I\'m using the jQuery Validator Plugin. My code is like this: <input name=\"username\" type=\"text\" class=\"newtextbox required\" rangelength=\"(4,16)\">

I'm using the jQuery Validator Plugin. My code is like this:

<input name="username" type="text" class="newtextbox required" rangelength="(4,16)">

The error message is "Please enter a value between NaN and 4 characters long". The actual error message that has to be is "Please enter a value between 4 and 开发者_运维百科16 characters long".

I think the HTML I have used is incorrect.

Can anyone help me out? Thanks in advance.


Try this:

<input name="username" type="text" class="newtextbox required" digits="true" min="4" max="16">


Try using square brackets instead:

<input name="username" type="text" class="newtextbox required" rangelength="[4,16]">

Still, you shouldn’t be defining this inside the HTML; you can do this with JavaScript.

$("#some-form").validate({
 rules: {
  field: {
   required: true,
   rangelength: [4, 16]
  }
 }
});

You can read more about the rangelength method of the jQuery Validation Plugin if you wish.


This is a bug in the plugin. See https://github.com/jzaefferer/jquery-validation/issues/447 for a patch.

0

精彩评论

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