I'm finding a regular expression which adheres below rules.
Allowed Characters
Alphabet : a-z A-Z Numbers : 0-9
I am using [^a-zA-Z0-9] but when call
regex = "[^a-zA-Z0-9]" ;
String key = "message";
if (!key.matches(regex))
message = "Invalid key";
system will show Invalid key, The key should be valid. Could you please help me?
String#matchesdo?[^chars]will match exactly one character that is not one of the[chars]. And also note thatString#matchesacts as if your regex is^regex$