0
votes

I am creating regex for password validation. Password must start with letter, and must contain 1 uppercase and 3 lowercase letters among the other things.

This is what I got

^[a-zA-Z](?=.*[A-Z])(?=.*[0-9].*[0-9])(?=.*[a-z].*[a-z].*[a-z])(?=.*[!@#$%^&*~].*[!@#$%^&~*])(?!.*(.)\1\1)[a-zA-Z0-9!@#$%^&*]{8,12}$    

If I start with uppercase letter and there is not any other uppercase, validation is negative. It is same for lowercase.

  • Aasd23#$s invalid
  • Aasd23#$sA valid
  • aAas23$%6$ invalid
  • aAas23$%6$a valid

Can someone help me?

1
Are you sure that at this point it's not easier to validate it by other means, if possible? - mszymborski
I've already spent too much time on this, so I have to finish - Milorad
Simply place the [a-zA-Z] behind the lookaheads. - Sebastian Proske
Isn't it there already? @SebastianProske - revo
@revo no, it's directly after the ^, thus evaluated before the lookaheads and not regocnigez inside those. - Sebastian Proske

1 Answers

0
votes

according to what you posted

^([a-zA-Z](?=(?:.*?[a-z]){3})(?=.*?[A-Z]).*)$

Demo