Java: Check if String only contains Numbers
Question by Guest | 2016-08-04 at 23:44
Is is there any possibility in Java to determine whether a string only contains numbers (digits from 0 to 9)?
I would like to test some user input before further processing and to show an error message if necessary.
Related Topics
PHP: Check Strings with Ctype-Functions for Character Classes
Article | 0 Comments
Java: Smaller/Larger Comparison of Strings - The operator > is undefined for the argument type(s) java.lang.String
Question | 1 Answer
Android Programming: Receive Responce from HTTP POST Request
Tutorial | 0 Comments
PHP: Remove all empty elements from string array
Tip | 0 Comments
Java: Case Insensitive Equals - String Comparison
Info | 0 Comments
Java: Split at point str.split(".") does not work
Question | 1 Answer
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
You can just use the function .isNumeric(). A string can be passed to this function and you get TRUE or FALSE as a result depending on the content of the string:
In this example, accordingly, only "123" would result in TRUE because the strings "ABC" and "1 3" are not only consisting of digits.
2016-08-05 at 13:04