Check if string is Integer with jQuery

what is a function that checks if a string is integer or not like a method:

jQuery.isNumeric() 

I want to check the html input element:

 <input id='distance' type='text' /> 

early

+6
source share
3 answers

Thanks for your contributions, I found the answer:

 if(Math.floor($('#distance').val()) == $('#distance').val() && $.isNumeric($('#distance').val())) { alert('yes its an int!'); } 
+9
source

I use this

 function IsInteger(n){ return Number(n) === n && n % 1 === 0; } 
-1
source

Sorry, I didn’t notice the integer when I answered, here is another type check:

 if($.type($(#distance).val())==="number") 

see: http://api.jquery.com/jquery.type/

-3
source

Source: https://habr.com/ru/post/975137/


All Articles