3

I'm having a hard time trying to create a right regular expression for the RegularExpressionValidator control that allows password to be checked for the following: - Is greater than seven characters. - Contains at least one digit. - Contains at least one special (non-alphanumeric) character.

Cant seem to find any results out there too. Any help would be appreciated! Thanks!

4 Answers 4

12

Maybe you will find this article helpful. You may try the following expression

^.*(?=.{8,})(?=.*[\d])(?=.*[\W]).*$

and the breakdown:

  • (?=.{8,}) - contains at least 8 characters
  • (?=.*[\d]) - contains at least one digit
  • (?=.*[\W]) - contains at least one special character
Sign up to request clarification or add additional context in comments.

Comments

0

http://msdn.microsoft.com/en-us/library/ms972966.aspx

Search for "Lookaround processing" which is necessary in these examples. You can also test for a range of values by using .{4,8} as in Microsoft's example:

^(?=.*\d).{4,8}$

Comments

0

Try this

((?=.*\d)(?=.*[a-z])(?=.*[\W]).{6,20})

Description of above Regular Expression:

(           # Start of group
  (?=.*\d)      #   must contains one digit from 0-9
  (?=.*[a-z])       #   must contains one lowercase characters
  (?=.*[\W])        #   must contains at least one special character
              .     #     match anything with previous condition checking
                {7,20}  #        length at least 7 characters and maximum of 20 
)           # End of group

"/W" will increase the range of characters that can be used for password and pit can be more safe.

Comments

0

Use for Strong password with Uppercase, Lowercase, Numbers, Symbols & At least 8 Characters.

//Code for Validation with regular expression in ASP.Net core.
[RegularExpression(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,15}$")]

Regular expression password validation:

@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,15}$"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.