We Recommend

Java How to Program Java How to Program
Takes a new tools-based approach to Web application development that uses Netbeans 5.5 and Java Studio Creator 2 to create and consume Web Services. Features new AJAX-enabled, Web applications built with JavaServer Faces (JSF), Java Studio Creator 2 and the Java Blueprints AJAX Components. Includes new topics throughout, such as JDBC 4, SwingWorker for multithreaded GUIs, GroupLayout, Java Desktop Integration Components (JDIC), and much more.


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.