更新时间:2023-01-22 19:03:58
使用Apache Commons Lang:
Using Apache Commons Lang:
!StringUtils.isAlphanumeric(String)
对String的字符进行交替迭代,并检查:
Alternativly iterate over String's characters and check with:
!Character.isLetterOrDigit(char)
您还有一个问题:
您的示例字符串abcdefà是字母数字的,因为à
是一封信。
You've still one problem left:
Your example string "abcdefà" is alphanumeric, since à
is a letter. But I think you want it to be considered non-alphanumeric, right?!
因此,您可能想使用正则表达式:
So you may want to use regular expression instead:
String s = "abcdefà";
Pattern p = Pattern.compile("[^a-zA-Z0-9]");
boolean hasSpecialChar = p.matcher(s).find();