CyrefJS
CCyrefJS
فا
Back to documentation
Validation/Since 1.38.0

isStrongPassword

Checks whether a value is a string that satisfies the utility's strong password requirements.

isStrongPassword(value):boolean

Password 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

valueunknownrequired

The value to validate as a strong password.

Returns

boolean

Returns true when the value satisfies all password requirements; otherwise returns false.

Examples

01

Valid password

A password with at least eight characters, uppercase and lowercase letters, a number, and a special character.

TypeScript
isStrongPassword("Hello123!");
// true
02

Too short

Passwords shorter than eight characters are rejected.

TypeScript
isStrongPassword("Ab1!");
// false
03

Missing character requirements

A password must contain an uppercase letter, lowercase letter, number, and special character.

TypeScript
isStrongPassword("password123!");
// false

isStrongPassword("PASSWORD123!");
// false

isStrongPassword("Password!");
// false

isStrongPassword("Password123");
// false
04

Whitespace

Passwords containing whitespace are rejected.

TypeScript
isStrongPassword("Hello 123!");
// false
05

Non-string value

Non-string values are rejected immediately.

TypeScript
isStrongPassword(12345678);
// false

isStrongPassword(null);
// false
Built with@cyref/js·Official documentation