Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery check if value is numeric

Tags:

I was wondering if anybody had a quick and dirty jquery method that will check if a value is numeric or not? I was thinking about using a regex type method to check the value, if not do not submit the form. I was using jquery validation, but I am running into issues just loading jquery validation.

I just have one value that I want to make sure is numeric.

like image 263
SoftwareSavant Avatar asked Jan 22 '13 17:01

SoftwareSavant


People also ask

Is Numeric in jQuery?

The isNumeric() method in jQuery is used to determine whether the passed argument is a numeric value or not. The isNumeric() method returns a Boolean value. If the given argument is a numeric value, the method returns true; otherwise, it returns false. This method is helpful as it decreases the lines of code.

How do you check if it is Not-a-Number in jQuery?

The $. isNumeric() method checks whether its argument represents a numeric value. If so, it returns true . Otherwise it returns false .

Is number validation in jQuery?

The jQuery $. isNumeric() method is used to check whether the entered number is numeric or not. $. isNumeric() method: It is used to check whether the given argument is a numeric value or not.


1 Answers

Sure, use jQuery's isNumeric() function.

$.isNumeric("-10");  // true $.isNumeric(16);     // true $.isNumeric(0xFF);   // true $.isNumeric("0xFF"); // true $.isNumeric("8e5");  // true (exponential notation string) $.isNumeric(3.1415); // true $.isNumeric(+10);    // true $.isNumeric(0144);   // true (octal integer literal) $.isNumeric("");     // false $.isNumeric({});     // false (empty object) $.isNumeric(NaN);    // false $.isNumeric(null);   // false $.isNumeric(true);   // false $.isNumeric(Infinity); // false $.isNumeric(undefined); // false 
like image 141
j08691 Avatar answered Oct 13 '22 14:10

j08691