Skip to content

Instantly share code, notes, and snippets.

@arielweinberger
Last active June 12, 2024 09:45
Show Gist options
  • Save arielweinberger/18a29bfa17072444d45adaeeb8e92ddc to your computer and use it in GitHub Desktop.
Save arielweinberger/18a29bfa17072444d45adaeeb8e92ddc to your computer and use it in GitHub Desktop.
Strong password Regular Expression - NestJS Course
  • Passwords will contain at least 1 upper case letter
  • Passwords will contain at least 1 lower case letter
  • Passwords will contain at least 1 number or special character
  • There is no length validation (min, max) in this regex!

Regular expression for JavaScript:

/((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/
@cyblogerz
Copy link

Thanks for this @arielweinberger 🔥

@seunAwonugba
Copy link

with class validator, you can also pass in a custom error message is its not a strong password
@IsStrongPassword({}, { message: STRONG_PASSWORD })
password: string;

export const STRONG_PASSWORD =
'Your password must be at least 8 characters long, contain at least one number and have a mixture of uppercase and lowercase letters';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment