Q:

How to check whether a value is numeric or not in jQuery

0

How to check whether a value is numeric or not in jQuery

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the jQuery.isNumeric() method

You can use the jQuery $.isNumeric() method to check whether a value is numeric or a number.

The $.isNumeric() returns true only if the argument is of type number, or if it's of type string and it can be coerced into finite numbers, otherwise it returns false.

Let's take a look at the following example to understand how it basically works:

<script>
    // Return true (numeric)
    $.isNumeric("-10")
    $.isNumeric("0")
    $.isNumeric(0xFF) /* Hexadecimal notation (0xFF represents the number 255) */
    $.isNumeric("0xFF")
    $.isNumeric(+10)
    $.isNumeric(1.25e2) /* Exponential notation (1.25e2 represents the number 125) */
    $.isNumeric("1.25e2")
    $.isNumeric("13.417")
    $.isNumeric(0144)
    $.isNumeric(-0x56)
     
    // Return false (non-numeric)
    $.isNumeric("-0x52")
    $.isNumeric("7.2xyz")
    $.isNumeric("")
    $.isNumeric({})
    $.isNumeric(NaN)
    $.isNumeric(null)
    $.isNumeric(true)
    $.isNumeric(Infinity)
    $.isNumeric(undefined)
</script>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to replace multiple spaces with single space i... >>
<< How to replace all occurrences of a string in Java...