regex – .NET Framework



Hi can anyone give me regex for validating password which should allow 9 characters exaclty and I numeric and 1 Uppercase any number of lower case letters..please………..
in advance


i think it depend on one’s requirement like ur’s is exactly 9 char, 1 number and 1 upper case. i have one for

"Password must be at least 4 characters, no more than 8 characters, and must include at least one upper case letter, one lower case letter, and one numeric digit"


now if u take out (?=.*[a-z]) from above, this will take lower char condition out, and change {4,8} to 9 .. and that should solve ur prob i suppose
just made it now, havnt tried it ever



Thanks for the reply but it isnot working 🙁


I concur – having made the suggested change to Jays example:


Works just fine in RegexBuddy…

Working with Regex takes a shift in mindset… instead of thinking of it as string that contains at least one upper case, one lower case and one numeric, you have to think of it like this.

Mandatory inclusions:

1). A start of string token (^) where the following conditions are true:the start token is followed by any number (note: any number may also mean no characters) of characters followed by a number. (?=.*\d)
the start token is followed by any number of characters followed by a lower case letter. (?=.*[a-z])
the start token is followed by any number of characters followed by an upper case letter. (?=.*[A-Z]) 2). 9 characters (.{9})
3). An end of string token ($)

If any of the numbered conditions doesn’t match, then the regex fails. So if the start isn’t followed by its conditions, then it’s not included, and therefore your inclusion list fails to find a matching start of string token.


I used this expression according to my requirement….(from the expression that you gave_)


do you find any thing missing in this?


By the way, my requirement doesnot care about the first character it can be anything…but overall it should contain 1 uppercase and 1 numeric

### @splendid9

I point to my note in my previous post: ANY number of characters may also mean NO characters:

.*[A-Z] could just be a single upper case character or could mean any series of characters where the last character is an upper case. This would be true for:
A aA aaA aaaA aaaaA … It’s not ignoring the first character… all we’re saying here is that unless you have a start token followed by 9 characters followed by an end token, the whole pattern will fail inspection.

The start token will fail inspection if the string following it doesn’t contain at least one upper case, at least one lower case and at least one numeric [it doesn’t care what else is in the string].

The string token (.{9}) will fail inspection if it’s not exactly 9 characters long.

The end of string token will fail if the preceding portion of the expression fails – it must be preceded by a successful start token (i.e. it matches our conditions) and a successful string token (9 characters).


Thanks Its working …………………..


No problem, glad you got it working…