Click here to Skip to main content
15,031,145 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i need:
- 12-15 characters
- contain at least 1 capital letter OR 1 special character
- contain at least 1 small letter
- contain at least 1 number

this is the regex i get so far, but still not complete yet.

Don't use a regex - it's not a "text matching" task.
Instead use code - by all means use a bunch of different regexes (or even a single regex to group the characters into their types) but check number and so forth in code - it's easier to wrote, and a lot easier to understand and maintain.

A regex to do that would be horribly difficult to understand - unlike the equivalent code.
Use this Regular expression :

<asp:RegularExpressionValidator ID="rev" runat="server" ControlToValidate="txt"
This will do the trick:

It's a series of positive lookaheads, which all verify a match without consuming any characters. Then the length validation consumes the entire string, if it's the correct length.

Match capital or special (this depends on your definition of "special"):

Match lowercase letter:

Match number:

Verify length (this is where you would also restrict any invalid characters):

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900