I need a method that can tell me if a String has non alphanumeric characters.
For example if the String is \"abcdef?\" or \"abcdefà\", the method must return true.>
Use this function to check if a string is alphanumeric:
public boolean isAlphanumeric(String str)
{
char[] charArray = str.toCharArray();
for(char c:charArray)
{
if (!Character.isLetterOrDigit(c))
return false;
}
return true;
}
It saves having to import external libraries and the code can easily be modified should you later wish to perform different validation checks on strings.