I’m not really good at regular expressions. I need to do the following to validate if a password, entered by the user, is correct or not.
Criteria:
- Must contain at least one number
- Must contain at least one letter from A-Z or a-z (case does not matter as long as they enter is a letter).
- The password must be a minimum of 8 characters
The first part (
(?=.*\d)) searches for at least one number, the second part ((?=.*[A-Za-z])) searches for at least one letter, and the last part (.{8,}) ensures it’s at least 8 characters long.You might want to put an upper limit on the length of the password like this:
The 30 in that spot limits it to 30 characters in length, and the ^ and $ anchor it to the start and end of the string.