I’ve only been trying it in Firefox’s JavaScript console, but neither of the following statements return true:
parseFloat(\'geoff\') == NaN;
parseFloat(\'ge
While @chiborg 's answer IS correct, there is more to it that should be noted:
parseFloat('1.2geoff'); // => 1.2
isNaN(parseFloat('1.2geoff')); // => false
isNaN(parseFloat('.2geoff')); // => false
isNaN(parseFloat('geoff')); // => true
Point being, if you're using this method for validation of input, the result will be rather liberal.
So, yes you can use parseFloat(string)
(or in the case of full numbers parseInt(string, radix)
' and then subsequently wrap that with isNaN()
, but be aware of the gotcha with numbers intertwined with additional non-numeric characters.