By definition, an integer value does not contain characters (apart from the minus sign), otherwise the value is invalid.
If you have a String and would like to check for foreign characters, you can try:
the matches() method using a regular expression.
For example, if you suspect alphabetic characters, you can check using:
if(someString.matches("[a-zA-Z]")
{
// do something
}
If you want to scan for all non-numeric characters, you can replace with
...matches("[^0-9]")...
Is there a method in Java in which to see if an integer value contains characters?
1 answer