Using Jquery validate plugin for negative value checking on change of the input box

javascript, jquery, jquery-validate

Solution

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?

Problem

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.

Original source

Related problems