Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
32
rated 0 times [  37] [ 5]  / answers: 1 / hits: 135446  / 12 Years ago, sun, april 22, 2012, 12:00:00

Possible Duplicate:

Check if a variable contains a numerical value in Javascript?






How do I check if variable is an integer in jQuery?



Example:



if (id == int) { // Do this }


Im using the following to get the ID from the URL.



var id = $.getURLParam(id);


But I want to check if the variable is an integer.


More From » jquery

 Answers
13

Try this:



if(Math.floor(id) == id && $.isNumeric(id)) 
alert('yes its an int!');


$.isNumeric(id) checks whether it's numeric or not

Math.floor(id) == id will then determine if it's really in integer value and not a float. If it's a float parsing it to int will give a different result than the original value. If it's int both will be the same.


[#86070] Saturday, April 21, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dillionsalvadorg

Total Points: 288
Total Questions: 103
Total Answers: 75

Location: South Korea
Member since Sat, Oct 2, 2021
3 Years ago
;