fork download
  1. class Ideone {
  2. public static void main (String[] args) {
  3. String[] tests = {"a1!", "a1", "1!", "a!"};
  4. for (String test : tests) {
  5. System.out.println(test + ": " + passwordValid(test));
  6. }
  7. }
  8. static boolean passwordValid(String password) {
  9. return password.matches("(?=.*[a-zA-Z])(?=.*\\d)(?=.*[!@#*+_(%?/{}\\[\\].,;:-]).*");
  10. }
  11. }
Success #stdin #stdout 0.15s 51296KB
stdin
Standard input is empty
stdout
a1!: true
a1: false
1!: false
a!: false