Checking for repeating characters

I am implementing quite strict username policies. I have managed to implement 90% of all the validators (such as "must contain at least one uppercase letter, at least one numeric character, no special characters etc). The username string can't contain more than 4 repeating characters, e.g. Bob123aaaaa. I have looked for regex to check for this, but I wasn't succesful. Any help?
Caroline_SwartAsked:
Who is Participating?
 
Fernando SotoConnect With a Mentor RetiredCommented:
Hi Caroline_Swart;

The following Regex pattern will detect 5 or more repeating characters.

        string pattern = @"(?<1>.)\k<1>{4,}";

Fernando
0
 
Caroline_SwartAuthor Commented:
Thank you very much, it worked first time and I didn't need to change a thing. Your help is appreciated.
0
 
Fernando SotoRetiredCommented:
Glad I was able to help. Have a great day. ;=)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.