How do you determine if a string represents a number?
The straightforward and potentially naive way is this:
function is_number(my_str) {
return !isNaN(parseInt(my_str));
}
However, the above does not work. Notice that the following all return true:
is_number("3, 4, 5");
is_number("3, (123)");
is_number("3, 123)");
is_number("3, (123) (and foo bar)");
is_number("3 apples and 2 oranges");
The issue is that parseInt seems to only look at the first word. Any idea on a more comprehensive solution here?