JavaScript / ECMAScript

Password (No Special Chars) in JS

Validate passwords requiring at least one lowercase, one uppercase, one digit, and minimum 8 characters — no special characters required.

Try it in the JS tester →

Pattern

regexJS
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[A-Za-z\d]{8,}$

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[A-Za-z\\d]{8,}$", "");
const input = "Password1";
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

Three positive lookaheads (?=.*[a-z]) (?=.*[A-Z]) (?=.*\d) require a lowercase letter, uppercase letter, and digit somewhere in the string. [A-Za-z\d]{8,}$ then matches 8+ alphanumerics. Lookaheads are zero-width so they don't consume — they're constraints, not consumers. Note: Go's RE2 does not support lookaheads, so this pattern won't compile there.

Examples

Input

Password1

Matches

  • Password1

Input

MyPass99

Matches

  • MyPass99

Input

weakpass

No match

Same pattern, other engines

← Back to Password (No Special Chars) overview (all engines)