Reputation: 821
what is the function which test if a string is an Integer or not like the method :
jQuery.isNumeric()
i want to test an input html element :
<input id='distance' type='text' />
thank you in advance
Upvotes: 6
Views: 30023
Reputation: 17
I use this
function IsInteger(n){
return Number(n) === n && n % 1 === 0;
}
Upvotes: -1
Reputation: 2132
sorry I didn't notice integer when I answered, here is another type check:
if($.type($(#distance).val())==="number")
please see: http://api.jquery.com/jquery.type/
Upvotes: -4
Reputation: 821
thank you for your contributions i found the answer :
if(Math.floor($('#distance').val()) == $('#distance').val() && $.isNumeric($('#distance').val()))
{
alert('yes its an int!');
}
Upvotes: 9