Regular expression help

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>
 
C

Cubaman

<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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top