I have a method to check my users input in a comment text field.
public boolean isValidComment(String commentString) {
String expression = "[a-zA-Z0-9_ ]+";
CharSequence inputStr = commentString;
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
return matcher.matches();
}
This works for me, but I need to change my pattern. The user should be able to type any character with the exception of these characters: <> {} [].
How do I set up the pattern to allow everything except those above?
Try this:
In ahother hand, you need to use a constant of
Patternfor avoid recompiled the expression every time, something like that:And use the constant: