Online Snippets Library

Check If Value is Numeric in jQuery

We will use jQuery.isNumeric() function of jQuery, to check value is numeric or not.

Example

HTML
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"> </script>
<title>Check If Value is Numeric in jQuery</title>
</head>
<body>
<input type="text" id="input" name="value">
<p id="result"></p>
<input id="button" type="button" value="Check Value" />
</body>
</html>
Javascript
$(document).ready(function(){
$("#button").click(function(){
if($.isNumeric( $('#input').val()))
 {
$('#result').html('Value is Numeric');
 }
else
 {
$('#result').html('Value is not Numeric');
 }
});
});

Here is list of sample return values.

$.isNumeric( "-18" ); // Value is Numeric
$.isNumeric(0xFC); // Value is Numeric
$.isNumeric(3.16); // Value is Numeric
$.isNumeric(+10 ); // Value is Numeric
$.isNumeric(''); // Value is not Numeric
$.isNumeric({}); // Value is not Numeric
$.isNumeric(NaN); // Value is not Numeric
$.isNumeric(null); // Value is not Numeric
$.isNumeric(true); // Value is not Numeric
$.isNumeric(Infinity); // Value is not Numeric
$.isNumeric(undefined); // Value is not Numeric