Regex (regular expression) password check with Java

Submitted by rex on Wed, 04/29/2009 - 18:13

Our String is
aaaaaZZaa44

and with the regular
((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{6,})

we check if our password contains at least one digit, one upper and lower case.
we also check the length of the password, if its greater than 6.

import java.util.regex.*;
public class RegexPwdCheck {

public static void main(String[] args) {

String passwd = "aaaaaZZaa44";
String pattern = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{6,})";
System.out.println(passwd.matches(pattern));

}
}

Add new comment