On the system I am working with, we have a Password class that validates by throwing exceptions under the following conditions:
public Password(string password)
: base(password)
{
// Must contain digit, special character, or uppercase character
var charArray = password.ToCharArray();
var hasDigit = charArray.Select(c => char.IsDigit(c)).Any();
var hasSpecialCharacter = charArray.Select(c => char.IsSymbol(c)).Any();
var hasUpperCase = charArray.Select(c => char.IsUpper(c)).Any();
if (!hasDigit && !hasSpecialCharacter && !hasUpperCase)
{
throw new ArgumentOutOfRangeException
("Must contain at least one digit, symbol, or upper-case letter.");
}
}
If I was going to write this same check for hasDigit, hasSpecialCharater, and hasUpperCase in JavaScript, what would it look like?
JavaScript does not have these same character prototypes, so I've got to use regular expressions, no?