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.

2
  • 1
    what's ('#.EmpNum')? i suppose you mean $("#EmpNum")..
    – Ya Zhuang
    Dec 1, 2011 at 15:01
  • The documentation is here: api.jquery.com/jQuery.isNumeric You have to understand the difference between methods and static functions... Dec 1, 2011 at 15:02

8 Answers 8

49

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

it's :jQuery.isNumeric(value)

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

15

Shouldn't it be more like...

if($.isNumeric($('#EmpNum').val()))
1
  • 1
    This answer is correct; here's the documentation to compliment his answer.
    – jabclab
    Dec 1, 2011 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() )
4

it should be like this

$.isNumeric($('#EmpNum').val());
0
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);
}
1

You Should use simple and easy way like:

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

if($.isNumeric(value))

{

//write your code here

}

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.

0
0

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

I had to use this:

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

$.isNumeric(temp);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.