jQuery验证未正确验证数字? [英] Jquery validation does not validate numbers properly?

查看:98
本文介绍了jQuery验证未正确验证数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了与使用jQuery不显眼的审定编号验证出现问题。
我使用的版本是:
ASP.MVC 3。
JQuery的1.9.1
JQuery用户界面1.10.1
jQuery验证1.11.0

I've got a problem with validation of numbers using jquery unobtrusive validation. The versions I'm using are: ASP.MVC 3. JQuery 1.9.1 JQuery UI 1.10.1 JQuery Validation 1.11.0

我想验证输入的是:

<input type="number" value="0" name="Data.time_between_loops.Planned.hour" id="Data_time_between_loops_Planned_hour" data-val-required="The hour field is required." data-val-range-min="0" data-val-range-max="23" data-val-range="The field hour must be between 0 and 23." data-val-number="The field hour must be a number." data-val="true" class="hour valid">

验证被执行的,但问题是,它是在该值作为字符串进行
即当我输入4,我得到验证错误。

The validation is performed, but the problem is that it is performed on the value AS a string, i.e. when I type 4 I get a validation error.

我看着jquery.validation的code和它看起来像它不会在值的任何(元素值,最小/最大)转换为数字,所以范围功能比较值是字符串。
我认为如果你设定的最小/最大范围jQuery中那么值将不会是字符串,但是当你指定它们的数据属性,他们是字符串和jQuery似乎并没有处理这个问题。

I looked at the code of jquery.validation and it looks like it does not convert the any of the values (element value,min/max) to a number, and so the range function compares the values are strings. I assume that if you set the min/max range in jquery then the values will not be strings, but when you specify them in data attributes they ARE strings and jquery does not seem to handle this.

这是准备jQuery验证错误还是我做错了什么?

Is this ready a bug in jquery validation or am I doing something wrong?

谢谢,
Nadav
我该如何解决这个问题?

Thanks, Nadav How do I fix this problem?

推荐答案

[数据类型(整数)]在MVC 3有效。
你可以做一个把戏。即
使文本框的类型=文本,并用JavaScript的盒子只接受数值验证。
那么你就可以通过验证范围验证控制。

[DataType(Integer)] is valid in MVC 3. you can do a trick. i.e. make the textbox type='text' and validate it with javascript that the box accept only numeric values. then you can validate the control by range validation.

这篇关于jQuery验证未正确验证数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆