Hello. I've been trying to get passwords on new user registrations restricted to have at least 1 uppercase letter, 1 lowercase letter, 1 number, no spaces, and be a minimum of 8 characters long. I'm pretty positive I've got the right regular expression (I got it off of regexlib.com) but for some reason it just does not want to work properly. Here's the expression: ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{8,}$ Code (markup): And here's the code for the control (textbox): <asp:TextBox ID="password" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="password" ErrorMessage="*" /> <asp:RegularExpressionValidator ID="RegularExpressionValidator3" ValidationExpression="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{8,}$" ControlToValidate="password" runat="server" ErrorMessage="!" /> Code (markup): Now, on the page, when I try to enter something like, Password12, it doesn't work. It DOES work if I change the {8,} to {2,} which makes no sense to me. Then when I try to use passord12W, it does NOT work, like it can't handle the uppercase letter at the end. I'm using VS2005 and ASP.NET 2.0. When I use the {8,}, it's requiring at least 14 characters or it wont work. By changing it to {2,} it only needs 8, but it still wont accept something like: hello12D Because there's no uppercase in the front, only in the back, even though order shouldn't matter. This is driving me crazy and makes no sense. I've done regular expressions before, in the same code even, and have never had such grief. All I want is to be able to handle a password with at least 1 uppercase, 1 lowercase, and 1 number and no spaces, in ANY order, being at least 8 characters long. Can someone please help me here? I've tried so many different combinations now I'm starting to lose track which is what. Thanks.
Here's a sample regex that MS provides to ensure that a password is longer than 7 digits, has one numeric, and one non-alpha-numeric " @\"(?=.{6,})(?=(.*\d){1,})(?=(.*\W){1,})" It doesn't deal with the 1 upper-case/1 lower-case alphabetic character that you want, but maybe it'll give you a step forward? Good luck, James
Hello and thanks for some help. I tried your suggestion and came up with this: (?=(.*\d){1,})(?=(.*[a-z]){1,})(?=(.*[A-Z]){1,})(?!(.*\s)).{5,} Code (markup): But unfortunately it still doesn't work and is random in it's behavior. I just can't figure it out... So very strange how it's dealing with it. Is there anything else on the page that might interfere with this? I know I have another regularexpressionvalidator, but it's for a completely different control...