1.38.0isStrongPassword
Checks whether a value is a string that satisfies the utility's strong password requirements.
isStrongPassword(value):booleanPassword requirements
The value must be a string with at least eight characters. It must not contain whitespace and must contain at least one uppercase letter, one lowercase letter, one digit, and one special character.
Whitespace
The validator rejects any value containing whitespace characters. It does not trim the password before validation.
Special characters
The password must contain at least one character matched by the utility's special-character pattern.
Type guard
The function is a TypeScript type guard. When it returns true, TypeScript narrows the value from unknown to string.
Parameters
valueunknownrequiredThe value to validate as a strong password.
Returns
booleanReturns true when the value satisfies all password requirements; otherwise returns false.
Examples
Valid password
A password with at least eight characters, uppercase and lowercase letters, a number, and a special character.
isStrongPassword("Hello123!");
// trueToo short
Passwords shorter than eight characters are rejected.
isStrongPassword("Ab1!");
// falseMissing character requirements
A password must contain an uppercase letter, lowercase letter, number, and special character.
isStrongPassword("password123!");
// false
isStrongPassword("PASSWORD123!");
// false
isStrongPassword("Password!");
// false
isStrongPassword("Password123");
// falseWhitespace
Passwords containing whitespace are rejected.
isStrongPassword("Hello 123!");
// falseNon-string value
Non-string values are rejected immediately.
isStrongPassword(12345678);
// false
isStrongPassword(null);
// false