Regualr Expression Password Matching
Is there a way in one single Reg Expression to validate a password string that satisfies,
1. Must have at least one upper case letter [A-Z]
2. Must have at least one lower case letter [a-z]
3. Must have at least one number [0-9]
4. Must have at least one special character from [! $ % ^ & * ( ) _ + = < > ? / \ | ] [ { }]
5. The string length should be between 6 and 25.
Note: The above said steps 1-4 characters can appear in any random order.
I have a solution, but the problem with this one is, I have to check for each named group,
"^((?<lower>[a-z])|(?<upper>[A-Z])|(?<number>[0-9])|(?<symbol>[\\$\\!\\%\\^\\#]))+$"
In C# code I would check as,
if (aMatch.Success && aMatch.Groups["lower"].Success
&& aMatch.Groups["upper"].Success && aMatch.Groups["number"].Success
&& aMatch.Groups["symbol"].Success)
{
Valid Password;
}
else
Not valid;
Is there a better solution, such as writing the whole thing in one Reg Expression?
Thanks,
Chandra
|