我正在使用 GeekTantra 中的 jQuery Live 表单验证
验证是通过 ID 调用的。下面是我用来为小于 50 的 2 位数字的字段设置选项的代码:
jQuery("#ValidNumber2Digits50").validate({
expression: "if (VAL.length <= 2 && !isNaN(VAL) && VAL < 50) return true; else return false;",
message: "Please enter a 2 digit number less than 50"
});
唯一的问题是它计算长度中的空格。 S0...
_4 ==> good data
4_==> good data
_9_ ==> bad data
_ _2 ==> bad data
我尝试过:
if (VAL.trim.length <= 2 && !isNaN(VAL) && VAL < 50) return true; else return false;
这不起作用。
有什么想法吗?
提前致谢。
最佳答案
trim()
是一个函数 - 尝试使用 $.trim(VAL).length
代替。
关于javascript - 将 .trim() 与 jquery 验证插件一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22972652/