I need a function that returns whether the given string contains at least x special characters.
I prefer it shouldn’t be hardcoded.
Pseudo code:
public bool IsValid(string password, int minSpecialCharacters)
{
if (!string.IsNullOrWhiteSpace(password))
return
password.Count(c => char.IsSpecialCharacter(c)) < minSpecialCharacters;
return true;
}
Use
char.IsLetterOrDigit, negated: