Greetings -
I've been tasked with coming up with an expression that would do password validation for our application. After doing a search for ideas I came across this site and this is the solution I was able to come up with:
Language: Java
Problem: A valid password is a minimum of eight characters and a maximum of sixteen. It contatins at least one lower case letter, one upper case letter and two digits. Using Expresso, this is the expression that seems to work: ^(?=.*[a-z].*[A-Z])(?=.*\d.*\d)[a-zA-A0-9]{8,16}$
What confuses me is that it works as expected in Expresso, but when I use the following Java snippet, the returned results are always false.
public boolean validatePassword (String password){
boolean isValid = false;
String passwordPattern = "^(?=.*[a-z].*[A-Z])(?=.*\\d.*\\d)[a-zA-A0-9]{8,16}$";
isValid = password.matches(passwordPattern);
return isValid;
}
Test passwords. "*" at the beginning denotes a vaild password:
12345678
* EJ91269126
A1!abcde
A12 abcde
* Ej91269126
* A12abcde
* A1a2bcde
* Ej9i29E26
1234567
Ej9i29E
* 3DM6m9TK
nT*z7t6h
* a1b3Vty7
!a1b3Vty7
_!a1b3Vty7
I admit that I'm new to using expressions, so I don't understand the nuances behind it, but this should be pretty straight forward right? What am I missing?
Thank you.