I have a textbox which letting user to enter their password.
My password format is

  1. Starting at least 1 non-alphanumeric
  2. Continue with alphanumeric
  3. Length: 7 and above.

What should i put in the validate expression?

<asp:RegularExpressionValidator ID="RegExpPass" runat="server" ErrorMessage="Password Length at Least 7 With Special Character" ControlToValidate="txtPass" ValidationExpression="^[a-zA-Z0-9'@&#.\s]{7}$" ForeColor="Red" />

^.*(?=.{7,})(?=.*[\d])(?=.*[\W]).*$
I Tested for this, it's so useful
1. Contain at least non-alphanumeric
2. Contrain at least numeric

But it doesn't allowed with alpha with non-alphanumeric, whereas non-alphanumeric with numeric is allowed.

how can i modify this code to become at least 1 non-alphanumeric with alphanumeric (no matter is full alpha or numeric is still allowing)

^.*(?=.{7,})(?=.[a-zA-Z])(?=.*[\d])(?=.*[\W]).*$

Thanks folk, i found the solution by keep searching the single thing and try it myself on TEST

  1. at least non-alphanumeric
  2. at least alphanumeric
RESULT
  • 1234567 Not Match
  • abcdefg Not Match
  • abc1234 Not Match
  • !abcdef Not Match
  • !123456 Not Match
  • !abc123 Match

By no means am I a regex expert but here is an example that meets the requirements.

 ^[._%+-/$][a-zA-Z0-9]{5}[a-zA-Z0-9]+$

There are other ways to write the regex but this requires the first to be a special character, then 5 more of alpha and numeric then one or more alpha and numeric characters.

I will suggest my expression at first,
because it is checking the whole string whether is containing those requirements, no matter where it is.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.