String s = ".... ;
System.out.println(s.matches(".*[^a-zA-z0-9].*"));
returns true if an illegal character is present.
Edit: But the first answer from jzd is better:
s.matches("[a-zA-Z0-9]+");
Returns true if an invalid character is missing, i.e. the line is good.
source
share