JavaScript’s isNaN() is so bad at validating numbers, it’s better off not using it at all. It doesn’t mean there is no way to validate numbers, you can easily write your own one.
function IsNumeric(input)
{
return (input - 0) == input && input.length > 0;
}
The (input – 0) expression forces the input value to first be interpreted as a number for the boolean compare. If that interpretation fails, the expression will result in NaN. Then this numeric result is compared to the original, unaltered value you passed in. If they are the same, we have a winner. The check on the length is of course for the empty string special case. So in other words, if you want to know if a value can be converted to a number, actually try to convert it to a number.