1

I currently have the following regex:

^(?!.*([A-Za-z0-9])\1{2})(?=.*[a-zA-Z])(?=.*\d)[A-Za-z0-9]+$

The entire thing will have the RegexOption.IgnoreCase set. So far it requires:

  • at least one letter anywhere
  • at least one number anywhere
  • not more than two of the same letter or number consecutively (aAa283 is bad, aa83Aa is fine)

I just need to change the "at least one letter" to "at least 3 letters". I've come up with the following, and it seems to work but I just need to be absolutely sure:

^(?!.*([A-Za-z0-9])\1{2})(?=(.*[a-zA-Z]){3})(?=.*\d)[A-Za-z0-9]+$
Aeon2058
  • 527
  • 6
  • 22
  • 1
    Your pattern works. `(?=(.*[a-zA-Z]){3})` can also be replaced with a more efficient `(?=(?:[^a-zA-Z]*[a-zA-Z]){3})`. Note that you may shorten the pattern (remove all `a-z` or `A-Z`) if you pass the case insensitive modifier. See [principle of contrast](http://www.rexegg.com/regex-style.html#contrast). – Wiktor Stribiżew Sep 22 '17 at 07:13

0 Answers0