Strong Password in JS
Enforce strong passwords: min 8 chars, at least one lowercase, uppercase, digit, and special character.
Try it in the JS tester →Pattern
regexJS
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^a-zA-Z\d\s]).{8,}$JavaScript / ECMAScript code
jsJavaScript
const re = new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[^a-zA-Z\\d\\s]).{8,}$", "");
const input = "MyP@ssw0rd";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
How the pattern 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@ssw0rdMatches
MyP@ssw0rd
Input
password123No match
—Input
SHORT1!No match
—