【发布时间】:2021-09-09 01:01:10
【问题描述】:
我想知道输入字段是否包含某些特殊字符,例如 。如果用户输入包含这些字符中的任何一个,它应该返回 true。
示例 :Robert# ,S%am
public static boolean isInvalidCharacters(String input) throws Exception {
try {
Pattern pattern = Pattern.compile("[^<(@#$%^&*>]");
Matcher matcher = pattern.matcher(input);
boolean isFound =matcher.find();
if (!isFound) {
return true;
} else {
return false;
}
} catch (Exception err) {
throw err;
}
【问题讨论】: