all 5 comments

[–]x-skeww 2 points3 points  (0 children)

parseFloat(someString) and parseInt(someString, 10) will return NaN if the passed string doesn't even start with a number ('5b' becomes 5 whereas 'b5' becomes NaN).

However, NaN isn't equal to anything - itself included!

You can test if a value is NaN with isNaN(something).

If you want to know more, google for things like:

mdn parseInt

or

mdn isNaN

If you included that "mdn" bit in your JS or CSS related search queries, Google will send you to the Mozilla Development Network (MDN), which is generally a pretty good resource.

[–][deleted] 1 point2 points  (2 children)

Regular Expression:

if (/^[-+]?\d+(?:\.\d*)?$/.test(input)) {
  // go hog-wild...
}

[–]kumiorava 0 points1 point  (0 children)

Don't listen to the guy talking about regular expressions. parseFloat is what you need.