Posted By

pablazo on 05/23/07


java String

Versions (?)

check if a string is a number

 / Published in: Java


  1. try {
  2. Double.parseDouble(yourString);
  3. } catch (NumberFormatException e) {
  4. // yourString ain't 10.6, that's for sure
  5. }

Report this snippet  


RSS Icon Subscribe to comments
Posted By: tonicharlot on August 14, 2008

Regex would probably be a better option here:

return yourString!=null && yourString.matches("\d{1-5}");

The above would return true for an input between 0 and 65535. Of course the regex used can be more realistic to take formatting and decimals into consideration.

You need to login to post a comment.