.net Regex for more than two consecutive letters

I am trying to write .Net Regex for more than two letters from the side.

aa - fine Aa - fine aaa - not allowed Aaa - not allowed 

I am new to regex, but so far this is what I put together.

 if (Regex.IsMatch(Password, @"/[^A-Za-z]{2}/")) return "Password cannot contain 3 consecutive same letters"; 

I'm not sure if this is close or not.

+1
regex
source share
1 answer

You need to remove the slashes (why are they there? It's not PHP) and you can use the ignore flag. How:

 Regex.Match(pw, @"(?i)(.)\1\1") 

What:

 Regex.Match(pw, @"(.)\1\1", RegexOptions.IgnoreCase) 

As Ilya G. commented

+5
source share

All Articles