The jQuery.isNumeric() utility returns true when a value is a finite number or a string that parses as one. This tutorial covers syntax, five worked examples from the official API, comparisons with isNaN(), form validation patterns, and values that fail the test.
01
Syntax
$.isNumeric(val)
02
Boolean
true / false
03
Number
10 yes
04
String
"10" yes
05
Finite
No NaN/∞
06
Forms
Input check
Fundamentals
Introduction
Form fields, plugin options, and AJAX payloads often arrive as strings — even when they represent numbers. Before you call parseInt, do math, or pass a value to a jQuery animation duration, you need to know whether the input is actually numeric.
jQuery provides jQuery.isNumeric() (also written $.isNumeric()) as a single boolean test. It accepts numbers and numeric strings, rejects empty strings, booleans, NaN, Infinity, and values like "10px" that only partially parse as numbers.
Concept
Understanding the jQuery.isNumeric() Method
jQuery.isNumeric(value) returns true only when value is a number or string whose entire content represents a finite numeric value. Internally jQuery checks the type, parses when needed, and verifies the result is not NaN or infinite.
Use it in validation helpers, slider widgets, quantity inputs, and anywhere user text must be confirmed as a plain number before calculation — not as a replacement for range checks or business rules.
💡
Beginner Tip
typeof x === "number" is true for NaN and Infinity. $.isNumeric(NaN) is false — that is why this utility exists.
Foundation
📝 Syntax
General form of jQuery.isNumeric:
jQuery
jQuery.isNumeric( value )
// or
$.isNumeric( value )
Parameters
value — any JavaScript value to test.
Return value
true if value is a finite number or numeric string.
false for all other types and non-numeric strings.
Minimal workflow
jQuery
var raw = $("#quantity").val();
if ($.isNumeric(raw)) {
var qty = parseFloat(raw);
}
Cheat Sheet
⚡ Quick Reference
Value
$.isNumeric()
10 / "10"
true
-10 / "-3.5"
true
0
true
""
false
true / {}
false
NaN / Infinity
false
"10px"
false
Compare
📋 $.isNumeric vs isNaN vs typeof
Three ways to inspect numbers — different strictness and coercion rules.
$.isNumeric
finite only
Number or numeric string; jQuery strict
isNaN
coerces
Surprises like isNaN("") === false
typeof
"number"
Includes NaN and Infinity
Number.isFinite
ES2015
Native finite number check
Hands-On
Examples Gallery
Each example uses $.isNumeric(). Open DevTools or use the Try-it links to run them interactively.
📚 Getting Started
Official jQuery API examples — numbers and numeric strings pass.
Example 1 — Numbers and Numeric Strings
The canonical passing cases from the jQuery documentation.
Empty strings, booleans, non-finite numbers, and strings with trailing units all fail. parseFloat("10px") returns 10, but isNumeric correctly rejects the full string.
Example 3 — Negative Numbers and Decimals
Floating-point values and their string forms are accepted.
Integers and decimals behave the same whether stored as numbers or read from text inputs. After validation, use parseFloat for math.
Example 4 — Validate a Form Field Before Submit
Guard quantity input — show an error when the value is not numeric.
jQuery
function validateQuantity(val) {
if (!$.isNumeric(val)) {
return "Enter a valid number";
}
var n = parseFloat(val);
if (n < 1) {
return "Minimum quantity is 1";
}
return "OK: " + n;
}
console.log(validateQuantity("5")); // OK: 5
console.log(validateQuantity("abc")); // Enter a valid number
For user-facing validation, prefer $.isNumeric over bare isNaN. In modern jQuery-free code, combine trimmed string checks with Number.isFinite(Number(s)) for similar strictness.
Applications
🚀 Common Use Cases
Form validation — quantity, age, price, and rating fields.
Plugin options — confirm duration, opacity, or index values are numeric.
Animation helpers — validate speed/delay before passing to .animate().
CSV / paste parsing — filter rows where a column should be numeric.
AJAX payloads — guard string fields that must parse as numbers.
Legacy jQuery UI — consistent numeric checks across older widgets.
🧠 How jQuery.isNumeric() Validates a Value
1
Check type
Only number and string types can proceed — others return false.
Type
2
Parse value
jQuery parses the string or number and compares parsing consistency.
Parse
3
Require finite
Reject NaN, Infinity, and strings that are not fully numeric.
Finite
4
✅
Return boolean
true only for valid finite numeric values.
Important
📝 Notes
Available since jQuery 1.7.
Accepts negative numbers and decimal strings.
Rejects hex strings like "0xFF" and strings with units like "10px".
Does not validate integer-only — use extra checks after isNumeric.
Whitespace-only strings typically fail — trim input first if needed.
Related: $.type() returns "number" for NaN — pair with isNumeric for input validation.
Compatibility
Browser Support
jQuery.isNumeric() has been part of jQuery since jQuery 1.7+. It works wherever jQuery runs — all modern browsers and legacy IE when paired with a supported jQuery build.
✓ jQuery 1.7+
jQuery jQuery.isNumeric()
Supported in jQuery 1.x, 2.x, and 3.x. Behavior is consistent across browsers because jQuery owns the validation logic.
100%With jQuery loaded
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
jQuery.isNumeric()Universal
Bottom line: Safe in any project that already includes jQuery. Without jQuery, validate with Number.isFinite(Number(trimmed)) on string inputs.
Wrap Up
Conclusion
The jQuery.isNumeric() utility is the jQuery way to confirm a value is a finite number or numeric string. It rejects the traps that typeof and isNaN leave open — empty strings, NaN, Infinity, and partial parses like "10px".
Use it before parseFloat on user input, then apply your own range and format rules — and explore jQuery.isPlainObject() when validating settings objects for $.extend().
jQuery.isNumeric(value) returns true when value is a finite number or a string that represents a finite number (such as "10" or "-3.5"). It returns false for empty strings, booleans, NaN, Infinity, and strings with extra characters like "10px".
Yes. Both 42 and "42" return true. The string must parse entirely as a number — partial matches like "12abc" or CSS values like "10px" return false.
isNaN coerces values and can produce surprising results — isNaN("") is false because "" coerces to 0. $.isNumeric("") is false. Use $.isNumeric for stricter finite-number checks in jQuery code.
Yes. -10, "-10", 3.14, and "3.14" all return true when they represent finite numbers.
Only finite numeric values pass. Infinity and NaN are typeof "number" in JavaScript but are not useful as ordinary numeric input — jQuery excludes them intentionally.
Validate text inputs before parseInt, parseFloat, or math — e.g. if ($.isNumeric($("#age").val())) { ... }. Pair with range checks after confirming the value is numeric.
Did you know?
jQuery added isNumeric in version 1.7 because plugin authors kept reimplementing the same parse-and-validate snippet. The official demo fits on one line — $.isNumeric("-10") — but the real value is rejecting "" and "10px", cases where raw parseFloat misleads beginners.