Paddy
Paddy

Reputation: 13

Regex for Password must contain 8 characters, 2 letter both lower or uppercase letters and one special character ' * ' 5 digit number

I want to create an expression for password as below:

Regex for passwords that must contain 8 characters, start with 2 lower or uppercase letters, contain one special character * and a 5-digit number.

E.g.: az*12345

I have tried it with this pattern: (?=(.*[^a-zA-Z]){2})(?=.*[*]{1})(?=(.*\d){5}).{8}$

However, it yields almost the same results as a regex above. It starts with any character but I want the exact above mentioned pattern. I know I am close to it. Please suggest me what I should do.

Upvotes: 1

Views: 4039

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627082

If you wish to match just [2-letters]+[*]+[5-digits] pattern, here is what you are looking for:

^[a-zA-Z]{2}\*[0-9]{5}$.

Upvotes: 2

Related Questions