parseInt integer too big
807588Feb 19 2009 — edited Feb 19 2009Hello,
In my application I have a form field which a non-negative number should be entered in.
In order to make my application maximally user-friendly, I validate that field if it has a value entered, if the value entered is a number and if the number entered is negative.
I validate the string with a Integer.parseInt() method. If it throws a NumberFormatException, then the input string is not a number (empty or text) and I display a message "The input string is not a number...". When it doesn't throw anything, then I validate the number to negativity.
But when I enter string "5000000000" (five billions), the result is NumberFormatException and the resulting message is "The input string is not a number...", which is obviously bad. Is there a way to know whether the NumberFormatException was thrown because of invalid string or because of too large number was entered?
Moreover, if value -5000000000 (minus five billions) was entered, I would like to display message "Input number must be non-negative...", instead of "Number too big...".
Thanks
Edited by: Shagrat on Feb 19, 2009 2:20 AM