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").. Commented 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... Commented 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())

Sign up to request clarification or add additional context in comments.

Comments

15

Shouldn't it be more like...

if($.isNumeric($('#EmpNum').val()))

1 Comment

This answer is correct; here's the documentation to compliment his answer.
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() )

Comments

4

it should be like this

$.isNumeric($('#EmpNum').val());

Comments

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);
}

Comments

1

You Should use simple and easy way like:

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

if($.isNumeric(value))

{

//write your code here

}

Comments

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.

Comments

0

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

I had to use this:

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

$.isNumeric(temp);

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.