How to check whether a value is numeric or not using jQuery ?

Given an input element and the task is to check whether the entered value is numeric or not using 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. If it is numeric then it returns true Otherwise returns false.

Syntax:



$.isNumeric( argument )

Example 1: This example uses jQuery .isNumeric() method to check entered element is numeric or not.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        How to check whether a value is
        numeric or not in jQuery?
    </title>
      
    <script src=
    </script>
</head>
  
<body style="text-align:center;">
      
    <h1 style = "color:green;"
        GeeksForGeeks 
    </h1
      
    <h3>
        How to check whether a value
        is numeric or not in jQuery?
    </h3>
      
    <hr>
      
    <form>
        <p>
            Enter any value: 
            <input style="text-align:center;" type="text">
        </p>
          
        <button type="button">Click to Check</button>
    </form>
    <hr>
      
    <script type="text/javascript">
        $(document).ready(function() {
            $("button").click(function() {
                var inputVal = $("input").val();
                alert($.isNumeric(inputVal));
            });
        });
    </script>
</body>
  
</html>          

chevron_right


Output:

  • Before entering the value:
  • Entering the value:
  • After click on the button:

Example 2: This example uses jQuery .isNumeric() method to check entered element is numeric or not.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        How to check whether a value
        is numeric or not in jQuery?
    </title>
      
    <script src=
    </script>
</head>
  
<body style="text-align:center;">
      
    <h1 style = "color:green;"
        GeeksForGeeks 
    </h1
      
    <h3>
        How to check whether a value 
        is numeric or not in jQuery?
    </h3>
    <hr>
      
    <form>
        <p>
            Enter any value: 
            <input style="text-align:center;" type="text">
        </p>
          
        <button type="button">Click to Check</button>
    </form>
    <hr>
      
    <h4></h4>
      
    <script type="text/javascript">
        $(document).ready(function() {
            $("button").click(function() {
                var inputVal = $("input").val();
                var gfg = $.isNumeric(inputVal);
                  
                if (gfg) {
                    $("h4").text("The Value Entered is Numeric");
                }
                else {
                    $("h4").text("The Value Entered is Not Numeric");
                }
            });
        });
    </script>
</body>
  
</html>  

chevron_right


Output:

  • Before Entering the value:
  • After entering the value and click on button:


My Personal Notes arrow_drop_up

Small things always make you to think big

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.