• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

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?
  • 2
1 Solution
Fernando SotoRetiredCommented:
Hi Caroline_Swart;

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

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

Caroline_SwartAuthor Commented:
Thank you very much, it worked first time and I didn't need to change a thing. Your help is appreciated.
Fernando SotoRetiredCommented:
Glad I was able to help. Have a great day. ;=)
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.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now