I have a password field where I want to have atleast one special character, atleast one uppercase character and atleast one numeric digit. Can anyone help me with the regex pattern please.
Thank You
I have a password field where I want to have atleast one special character, atleast one uppercase character and atleast one numeric digit. Can anyone help me with the regex pattern please.
Thank You
Pattern pwPattern = Pattern.compile("(?=.*[@#$!\"&])(?=.*[A-Z]).*\\d.*");
Add more special characters inside the first brackets if you want to allow more, I just added a few.
Use it like this:
if (pwPattern.matcher(passWordToTest).matches()) {
...
}
.* at the end even when the pw does not end with a digit..matches().^ into the character class, do it at the end of the class; if you insert -, do it at the start. Otherwise they change the meaning of what's in the class..find() in my test.