I need help with a .NET Regex password expression

Posted on 2011-10-11
Last Modified: 2012-05-12
The requirements for the expression are:
- No more than two characters can repeat
- Minimum size of 8 characters
- Must contain a least one upper case character
- Must contain a least one special character
- Must contain at least one numeric digit

I have already tried Reglib but am not familiar enough with them to create this expression. Any suggestions?

Thank you for your help
Question by:Elliott Ward
    LVL 34

    Expert Comment

    by:Terry Woods
    By "No more than two characters can repeat" I interpret this as allowing:
    but not

    Try this (I'm just about to test it now though!):
    LVL 34

    Expert Comment

    by:Terry Woods
    After testing, I needed to make a minor change. This appears to work:
    LVL 34

    Accepted Solution

    In VB.NET, hopefully this will work:
    Dim re As Regex = New Regex("^(?=.*[-`~!@\#$%\^&*()_+=\[\]{}\\|;':"",./<>?])(?=.*\d)(?=.*[A-Z])(?:(?!(.)\1\1).){8,}$")

    (Code generated by
    LVL 74

    Assisted Solution

    by:käµfm³d 👽
    If by "no more than two characters can repeat" you mean any single character can appear no more than one time in the password then change this part of Terry's pattern:


    Open in new window



    Open in new window


    Author Closing Comment

    by:Elliott Ward
    Thank you both for your assistance. This is exactly what I needed.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now