[英]Using Jquery validate plugin for negative value checking on change of the input box
I have multiple input boxes and I have to check whether the entered values are positive or negative using jquery Validator plugin . 我有多个输入框,我必须使用jquery Validator插件检查输入的值是正还是负。
It is basically doing some calculation based on the value entered in the first input box. 它基本上是根据在第一个输入框中输入的值进行一些计算。
The value entered must be positive, if not I should throw an error message saying the value must be positive or greater than zero. 输入的值必须为正数,否则我应该抛出一条错误消息,说明该值必须为正数或大于零。
Use the min
rule to specify that the minimum value is 1. 使用min
规则指定最小值为1。
$("#formid").validate({
rules: {
fieldname: {
min: 1
},
messages: {
fieldname: {
min: "Value must be greater than 0"
}
}
});
You can use regex for validating numeric value. 您可以使用正则表达式验证数值。 Code given below. 代码如下。 The function will return true if input box contains numeric value (negative or positive) 如果输入框包含数值(负数或正数),该函数将返回true
function checkNumericValue(num)
{
var objRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
return objRegExp.test(num);
}
For checking -ve value, follow the link How to check the value given is a positive or negative integer? 要检查-ve值,请点击链接如何检查给定的值是正整数还是负整数?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.