最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using Jquery validate plugin for negative value checking on change of the input box - Stack Overflow

programmeradmin0浏览0评论

I have multiple input boxes and I have to check whether the entered values are positive or negative using jquery Validator plugin.

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.

I have multiple input boxes and I have to check whether the entered values are positive or negative using jquery Validator plugin.

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.

Share Improve this question edited Nov 12, 2017 at 7:42 Callat 3,0445 gold badges33 silver badges49 bronze badges asked Aug 6, 2013 at 5:50 Java QuestionsJava Questions 7,95343 gold badges119 silver badges177 bronze badges 2
  • post the some code you have, have tried or the one you have so far – Sergio Commented Aug 6, 2013 at 5:52
  • 1 Use the min: 1 rule. – Barmar Commented Aug 6, 2013 at 6:15
Add a comment  | 

2 Answers 2

Reset to default 13

Use the min rule to specify that the minimum value is 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)

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?

发布评论

评论列表(0)

  1. 暂无评论