continual expression to check if password is "8 characters including 1 uppercase letter, 1 one-of-a-kind character, alphanumeric characters" (14 answers)
I require a regular expression for a password. The password has to contain at the very least 8 characters. At the very least one character have to be a number or a unique character (not a letter).

You are watching: Your password must contain at least 1 non-alphanumeric character(s)

"(?=.*W)?(?=.*d)", ErrorMessage = "Error message")>public wire Password get; set; I have a size validation, yet I need help with a constant expression the checks if the password consists of at least one number or distinct character.

Examples of valid passwords:

testtest85*testtes*testtes1test1234*+Examples of not valid passwords:




Use regex pattern ^(?=.8)(?=.*<^a-zA-Z>)


^(?=.8)(?=.*<^a-zA-Z>)│└──┬───┘└──────┬──────┘│ │ ││ │ └ string includes some non-letter character│ ││ └ string contains at least 8 characters│└ begining of line/stringIf you desire to limit likewise maximum length (let"s say 16), then usage regex pattern:



Run it through a relatively simple regex: <^a-zA-Z>

And then inspect it"s length separately:

if(string.Length > 7)


The StringLength(..., MinimumLength = 8) attribute that's currently in the question need to suffice come enforce a minimum length, so there shouldn't be a need to explicitly re-check (though it can't hurt, i suppose).
JV regexpal provides JavaScript regexes, no .NET regexes. However as girlfriend mention, top top cashmere's link, it works too.
"(?=.7)"); match1.Success ensures that there space at the very least 8 characters.

Match match2 = Regex.Match(, <^a-zA-Z>);match2.Success ensures that there is at least one distinct character or number within the string.

So, match1.Success && match2.Success assures will acquire what girlfriend want.


I do the efforts Omega"s example but it was not working v my C# code. Ns recommend using this instead:

"Error. Password must have actually one capital, one special character and one number character. It have the right to not start with a distinct character or a digit.")>
An expression choose this:

*<0-9+*>*should work simply fine (obviously insert any additional special characters you desire to enable or usage ^ operator to match anything other than letters/numbers); no need to use complicated lookarounds. This method makes feeling if you just want to permit a certain subset of special characters that you recognize are "safe", and disallow every others.

If you desire to encompass all special characters except specific ones which you recognize are "unsafe", then it renders sense to usage something like:

w<^\>*<^a-zA-Z\><^\>*In this case, girlfriend are clearly disallowing backslashes in her password and enabling any combination with at the very least one non-alphabetic personality otherwise.

See more: 225 Cadman Plaza East Brooklyn Federal Courthouse, Directions To Brooklyn Courthouse

The expression above will match any type of string containing letters and at the very least one number or +,*. As for the "length of 8" requirement, theres really no factor to examine that utilizing regex.

enhance this price
edited Aug 21 "12 at 13:03
reply Aug 21 "12 at 12:47
4,17722 yellow badges2121 silver- badges2121 bronze title
If you list the permitted characters in passwords, you're staying clear of me indigenous using more secure passwords. You have to look at it the other method around (as in J V's answer): if any character is not a letter, climate the password passes the check.
Aug 21 "12 at 12:51
include a comment |
role randomPassword(length) { var chars = "abcdefghijklmnopqrstuvwxyz#$%ABCDEFGHIJKLMNOP1234567890"; var happen = ""; for (var x = 0; x try this to develop the random password v atleast one one-of-a-kind character

improve this answer
answered january 5 "17 at 8:06
6911 silver- badge22 bronze title
include a comment |

Not the price you're spring for? Browse various other questions tagged c# regex validation or questioning your very own question.

The Overflow Blog
Featured ~ above Meta
Regular expression to check if password is "8 personalities including 1 uppercase letter, 1 distinct character, alphanumeric characters"
regular expression to inspect if a provided password contains at least one number and also one letter in c#?
continuous expression to inspect if password is "8 personalities including 1 uppercase letter, 1 one-of-a-kind character, alphanumeric characters"
Regex because that password need to contain at the very least eight characters, at the very least one number and both lower and uppercase letters and also special personalities
Regex because that Password: "Atleast 1 letter, 1 number, 1 special character and SHOULD NOT begin with a distinct character"
RegExp : At the very least 10 characters, through 1 upper case letter, v one lower instance letter and also or 1 distinct character or number)
Regex for password have to contain precisely one uppercase character
Regex for password of minimum 8 characters, consisting of at the very least 3 the these: uppercase character, lowercase character, number and special character
solid password examine
warm Network concerns more hot inquiries
ridge Overflow
stack Exchange Network
site design / logo © 2021 ridge Exchange Inc; user contributions license is granted under cc by-sa. Rev2021.11.11.40719

Stack Overflow works ideal with JavaScript enabled

her privacy

By clicking “Accept all cookies”, you agree ridge Exchange deserve to store cookies on your an equipment and disclose details in accordance with our Cookie Policy.