25

I have a text box with an id of EmpNum. I cannot figure out how to use jQuery's isNumeric to check to see if the value is numeric or not.

I tried:

    ('#.EmpNum').IsNumeric 

but that did not work.

Nate Pet
  • 44,246
  • 124
  • 269
  • 414

8 Answers8

49

according to http://api.jquery.com/jQuery.isNumeric/

it's :jQuery.isNumeric(value)

so, it should be $.isNumeric($("#EmpNum").val())

Ya Zhuang
  • 4,652
  • 31
  • 40
15

Shouldn't it be more like...

if($.isNumeric($('#EmpNum').val()))
w5m
  • 2,286
  • 3
  • 34
  • 46
Laurence Burke
  • 2,348
  • 14
  • 26
  • 1
    This answer is correct; here's the [documentation](http://api.jquery.com/jQuery.isNumeric/) to compliment his answer. – jabclab Dec 01 '11 at 15:02
5

Pass in the value as an argument to isNumeric. Also make sure you are using jQuery version 1.7 as this was added in 1.7.

$.isNumeric( $('#EmpNum').val() )
aziz punjani
  • 25,586
  • 9
  • 47
  • 56
4

it should be like this

$.isNumeric($('#EmpNum').val());
Ullas
  • 11,450
  • 4
  • 33
  • 50
homi
  • 201
  • 5
  • 5
2

Depending on what version of jQuery you are using, but as "$.isNumeric()" function is deprecated (https://jquery.com/upgrade-guide/3.0/#breaking-change-jquery-isnumeric-and-custom-tostring) since jQuery Core 3.0 Update, I found a custom solution for this problem (originally posted here: https://stackoverflow.com/a/9716488/3323790):

function isNumeric(n) {
    return !isNaN(parseFloat(n)) && isFinite(n);
}
IVIike
  • 87
  • 8
1

You Should use simple and easy way like:

var value=$('#txtNumber').val();

if($.isNumeric(value))

{

//write your code here

}

0

For me $.isNumeric($('#EmpNum').val()); did not work.

I had to use this:

var temp = $('#EmpNum').val();

$.isNumeric(temp);
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
0

Try the following:

$.isNumeric($('#EmpNum').text())

Also the isNumeric method was only added in version 1.7, which version are you using?

See here for jsFiddle.

Rich O'Kelly
  • 41,274
  • 9
  • 83
  • 114