password-validator
v5.3.0 · zero-config · fluent API

Passwords,
validated your way.

Describe the rules you want in plain, chainable English. The schema does the rest.

$npm install password-validator
0
dependencies
v5.3.0
latest release
MIT
licensed
// spin up a schema
const schema = new PasswordValidator();

schema
  .is().min(8)
  .has().uppercase()
  .has().digits(2)
  .has().not().spaces();

schema.validate('PaSs42word');
// → true 🎉

Try it live

toggle rules, type a password →
Rules
8
2
✗
INVALID
schema.validate() → false
✗at least 8 characters
✓an uppercase letter
✓a lowercase letter
✓at least 2 digits
✓no spaces
Generated schema
const schema = new PasswordValidator();
schema
.is().min(8) // at least 8 characters
.has().uppercase() // an uppercase letter
.has().lowercase() // a lowercase letter
.has().digits(2) // at least 2 digits
.has().not().spaces(); // no spaces
.validate(pw, { list: true }) → [ 'min' ]