jQuery isNumeric() method

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. It also returns true for Hex number, octal integer, negative numbers, decimal numbers, and also for exponential strings.

Syntax

This method accepts a single mandatory parameter that can be of any type. The parameter argument in the above syntax represents the value to be tested.

Let's see some of the illustrations to understand the concept of isNumeric() method.

Example1

In this example, we are passing some values to the isNumeric() method to check whether the values are numeric or not. If the passed values are numeric in nature, the isNumeric() method will return true, otherwise, it will return false.

Here, there are two div elements in which the first div element show the set of values for which the isNumeric() method returns true. The second div element shows the set of values for which the isNumric() method returns false.

Test it Now

Output

After the execution of the above code, the output will be -

jQuery isNumeric() method

Example2

In this example, we are using the isNumeric() method to check whether the value entered by the user is numeric or not. Here, there is a text field for taking the user input, and a button to check the input. We have to enter a value in the given text field, and then we have to click the given button to check whether the entered value is numeric or not.

Test it Now

Output

After the execution of the above code, the output will be -

jQuery isNumeric() method

On entering a numeric value and clicking the given button, the output will be -

jQuery isNumeric() method

On entering a non-numeric value and clicking the given button, the output will be -

jQuery isNumeric() method