0

I have a regex that is supposed to allow at least 1 number and 1 capital aswell as being between 4 and 15 characters. I hard coded some normal data to test but it always returns false.

public static bool PasswordValid(string password)
{
    Regex regex = new Regex(@"^(?=.*\d)(?=.*[a - z])(?=.*[A - Z]).{4,15}$");
    return regex.IsMatch("Password1");
}
Connor
  • 49
  • 5
  • 7
    Try it without the spaces in the character class `[a-z]` and `[A-Z]` – The fourth bird Jan 08 '20 at 14:14
  • 4
    Remove the spaces from your character classes. `[A - Z]` is not equivalent to `[A-Z]` in regex. –  Jan 08 '20 at 14:15
  • This is a common copy/paste issue with Visual Studio guys, I believe OP has no spaces inside the brackets. The point here is that the pattern also requires at least one lowercase letter, and that is not listed as a requirement. – Wiktor Stribiżew Jan 08 '20 at 14:39

0 Answers0