I need a regular expression for a password. The password has to contain at least 8 characters. At least one character must be a number or a special character (not a letter).
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 8)]
[RegularExpression(@"(?=.*\W)?(?=.*\d)", ErrorMessage = "Error message")]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
I have a length validation, but I need help with a regular expression that checks if the password contains at least one number or special character.
Examples of valid passwords:
testtest85*
testtes*
testtes1
test1234*+
Examples of not valid passwords:
testtest
testabc