Posted By

pablazo on 05/23/07


Tagged

java String


Versions (?)

check if a string is a number


 / Published in: Java
 

URL: http://forum.java.sun.com/thread.jspa?threadID=586718&messageID=3024348

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

Report this snippet  

Comments

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.