1

I want to set the valid number from -1 to infinity in the jquery validate rules, but how should i specify the number range. In from i specified "-1" and its working but in to what should be the value.

rules: {
                "numberOfUsers": {
                    "required": true,
                    "number":true,
                    "range":[-1,1000]
                }

-- Thanks

1 Answer 1

4

Infinity is displayed when a number exceeds the upper limit of the floating point numbers, which is 1.7976931348623157E+10308.

rewrite your rules like this

rules: {
                "numberOfUsers": {
                    "required": true,
                    "number":true,
                    "range":[-1,1.7976931348623157E+10308]
                }

or simply use this

rules: {
                    "numberOfUsers": {
                        "required": true,
                        "number":true,
                        "range":[-1,Infinity]
                    }
Sign up to request clarification or add additional context in comments.

5 Comments

If you want to do this, why not use Infinity itself?
Thanks for your answer, Also just curious, can we specify a series of range instead of using regex, like -1, & 1 - Infinity skipping zero i.e., zero is invalid value.
if you want to skip zero when you loop thru the range if zero occurs just use continue; statement from your loop to skip zero
Do i have to write a "customValidation" method?
something like this -- "required": function(element){ if($("#org-users-input").val() === 0){ return false; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.