Verify a string contains only numeric value in Java

The below example shows how to verify that a string contains only numeric values in Java. String may contain float value, double value etc. This example uses regular expression to check a string contains only numeric values. This method will not throw any exception.
Below is the method which validates a string contains only numeric values.

 

Below is the test method which gives the expected result from the above method.

 

Output

 

Thanks for reading. Please do not forget to leave a comment.

Soumitra

Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.