I have the following regex in c sharp to check if supplied password is
Regex.IsMatch(password, "^.*(?=.{10,})(?=.*[0-9]|[@#$%^&+=])(?=.*[a-z])(?=.*[A-Z]).*$")
Why wouldn't the above work?
its taking abcdefgh123
but not abcdefgh&+
Personally I'd do a separate check for the length and then one check for each of the character requirements. I don't like to use overly complicated regular expressions when things can be done in a more readable manner.
if (password.Length > 10 &&
Regex.IsMatch(password, "[a-b]") &&
Regex.IsMatch(password, "[A-Z]") &&
Regex.IsMatch(password, "[0-9@#$%^&+=]"))
{
//Valid password
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With