What Does jQuery $.isNumeric Evaluate?

The jQuery $.isNumeric() method evaluates whether its argument represents a valid, finite numeric value, returning true for actual numbers and numeric strings, and false for everything else. This article breaks down how the function operates under the hood, details the specific inputs it accepts and rejects, and explains how its evaluation logic differs from native JavaScript type checking.

How the Evaluation Works

Under the hood, jQuery defines a numeric value as something that can be parsed as a float and is finite. Internally, the evaluation relies on a check equivalent to:

!isNaN(parseFloat(obj)) && isFinite(obj)

Because of this implementation, $.isNumeric() checks for value usability rather than strict JavaScript data types. It tests whether an input can be safely treated as a number in mathematical operations.

Values That Evaluate to True

The function returns true for any input that represents a valid number:

  • Integers and Floating-Point Numbers: Native numbers such as 42, -10, 0, and 3.14159.
  • Numeric Strings: String representations of numbers such as "42", "-10", "0", and "3.14159".
  • Exponential/Scientific Notation: Both numbers and strings using exponential format, like 1e5, "1e5", 2e-3, or "-3e4".
  • Hexadecimal Numbers: Hexadecimal literals such as 0xFF or their string equivalents like "0xFF".
  • Leading/Trailing Whitespace with Numbers: Strings with surrounding spaces that contain only numbers, such as " 123 ".

Values That Evaluate to False

Unlike the native typeof operator or simple loose equality checks, $.isNumeric() strictly rejects values that cannot represent a finite number:

  • Empty and Whitespace Strings: "" and " " return false.
  • Non-Numeric Strings: Any string containing characters that cannot be fully converted into a number, such as "abc", "12a", or "px10".
  • Booleans: Both true and false return false (unlike native coercion where true becomes 1).
  • Special Number Values: NaN, Infinity, and -Infinity evaluate to false.
  • Null and Undefined: Both null and undefined return false.
  • Arrays and Objects: [], [1], and {} return false.
  • Functions and Symbols: Any function reference or JavaScript Symbol returns false.

Difference from Native JavaScript Checks

Standard JavaScript methods often produce counterintuitive results when validating numbers:

  • typeof NaN === "number" evaluates to true.
  • isNaN("") evaluates to false because empty strings coerce to 0.
  • isNaN(true) evaluates to false because booleans coerce to 1.

jQuery’s $.isNumeric() bypasses these edge cases by ensuring that empty strings, booleans, and non-finite numbers are filtered out, making it a reliable way to validate form inputs, API data, and URL parameters before performing calculations.