javascript - Getting a integer value from a textbox, how to check if it's NaN or null etc? -
I am pulling a value from a text box via javascript. If the text box is empty, then it returns NaN I want to return an empty string if it is empty, empty, etc.
What do I check? if (NAN = tb.value) ?
Hm, something is wrong here
What is the blank text box NaN in the browser? I have never seen this, and I can not reproduce it.
The value of a text box, is actually a string. Empty text box returns empty string!
Oh, and to check if something is not enough, you should use it:
if (nnn (tb.value)) {...} < / Code> Note: For any item isNa () -function returns can not be parsed as a number except for return true For the empty string it means that this is a good test for numerical input (easier than regexes):
if (tb.value! = "" & Amp;! IsNa (tb.value)) {// This is a number numValue = parseFloat (tb.value); }
Comments
Post a Comment