Regular expression help

  • Thread starter Thread starter DavidC
  • Start date Start date
D

DavidC

I am trying to implement a NewPasswordRegularExpression in a ChangePassword
control. Below is my control. I was testing with the following new password
attempt

mi11ard$

and it failed with the error message. I copied this from a Microsoft
example. Can anyone help with this? Thanks.

<asp:ChangePassword ID="ChangePassword1" runat="server"
NewPasswordRegularExpression =
'@\"(?=.{7,})(?=(.*\d){1,})(?=(.*\W){1,})'
NewPasswordRegularExpressionErrorMessage = "Your password must
be at least 7 characters long, and contain at least one number and one
special character."
PasswordHintText = "Please enter a password at least 7
characters long, containing a number and one special character.">
</asp:ChangePassword>
 
<snip>

I've tried this usinghttp://regex.cryer.info(an online regular expression
tester) and I agree that your pattern doesn't match.

But I think the problem is with your pattern:

'@\"(?=.{7,})(?=(.*\d){1,})(?=(.*\W){1,})'

its the @\" at the front which looks wrong, as this is saying that your
string (password in your case) must start with @" and indeed @"mi11ard$ does
match. If you remove the @\" then mi11ard$ it does match, so:

'(?=.{7,})(?=(.*\d){1,})(?=(.*\W){1,})'

but whether its doing what you want is another matter, as I'm not familiar
with (?=...) construct.

Hope this helps.

I think that David copied the wrong string. The "@" is for verbatim
literal. Regex should be like:

<asp:ChangePassword ID="ChangePassword1" runat="server"
NewPasswordRegularExpression =@"\"(?=.{7,})(?=(.*\d){1,})(?=(.*\W)
{1,})" />.

Read more about verbatim strings here:
http://www.c-sharpcorner.com/Upload...terals11262005010742AM/verbatim_literals.aspx

Best regards.
 
Back
Top