Take the 2-minute tour ×  As you know, the javascript's
parseFloat function works only until it meets an invalid
character, so for example  parseFloat("10.123") = 10.123
parseFloat("12=zzzz") = 12 parseFloat("z12") = NaN  Is there a
way or an implementation of parseFloat that would return NaN if
the whole string is not a valid float number?  share|improve
this question add comment  3 Answers  up vote 15 down vote
accepted  Use this instead:  var num = Number(value);  Then you
can do:  if (isNaN(num)) {     // take proper action
share|improve this answer This is a better idea than my answer
:) –  rfunduk Jul 15 '10 at 15:30 Just be careful about some
specific cases, e.g.: isNaN(parseFloat("")); // true and
Number("") == 0; // true –  CMS Jul 15 '10 at 15:38 @exoboy -
You don't need to deal with illegal characters with this
solution. Try this and you'll see: var x = Number("#!"); if
(isNaN(x)) alert("bad"); –  dcp Jul 15 '10 at 16:01 @exoboy -
I'm not sure I understand, when I run your example I get NaN for
num