特定の文字列に特殊文字が存在するかどうかを確認する単純な正規表現を書きたいと思います。私の正規表現は機能しますが、すべての数値も含まれている理由がわからないため、数値を入力するとエラーが返されます。
私のコード:
//pattern to find if there is any special character in string
Pattern regex = Pattern.compile("[$&+,:;=?@#|'<>.-^*()%!]");
//matcher to find if there is any special character in string
Matcher matcher = regex.matcher(searchQuery.getSearchFor());
if(matcher.find())
{
errors.rejectValue("searchFor", "wrong_pattern.SearchQuery.searchForSpecialCharacters","Special characters are not allowed!");
}