PDA

View Full Version : How to test if the passed value is an integer?



k0smita
24 Feb 2011, 2:58 AM
Is there any built-in in ExtJS to test if the passed value is an integer?

Ext.isNumber only checks if it's a number in general.

Condor
24 Feb 2011, 3:38 AM
Define 'integer'. You want to know if it is a whole number? Or do you want to know if a string contains a valid number?

k0smita
24 Feb 2011, 4:33 AM
Define 'integer'.

Heh, good question. In fact, in JavaScript '9' (String) sometimes is as good as 9 (Number). Both can be used as array index 9 for example. You can also do 2+true that gives 3. I forgot about all of these ;-)

So, after you question, I think a general "isInteger" function does not make sense and most likely does not exist in ExtJS - it depends what user wants to do later with the passed value and which types that can behave like integers to accept.

Thanks for forcing me to think more about dynamic typing in JS ;-)