Security

Strong Password

Enforce strong passwords: min 8 chars, at least one lowercase, uppercase, digit, and special character.

Try it in RegexPro →

Available in

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[^a-zA-Z\\d\\s]).{8,}$", "");
const input = "MyP@ssw0rd";
const match = input.match(re);
console.log(match ? match[0] : null);

Uses `String.prototype.match`, which returns the first match or null.

Pattern

regexengine-agnostic
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^a-zA-Z\d\s]).{8,}$

Raw source: ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^a-zA-Z\d\s]).{8,}$

How it works

Uses four lookaheads from the start (^) to assert each required character class exists somewhere in the string, then .{8,} ensures minimum length, and $ anchors the end.

Examples

Input

MyP@ssw0rd

Matches

  • MyP@ssw0rd

Input

password123

No match

—

Input

SHORT1!

No match

—

Common use cases

  • •User registration form validation
  • •Password policy enforcement
  • •Admin panel access controls
  • •Security compliance checks

Related patterns

Related concepts