Skip to content

Instantly share code, notes, and snippets.

@arielweinberger
Last active April 30, 2025 09:54
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]).*$/
@VincentBernier35
Copy link

Many thanks, this course is great !

@mattstuhring
Copy link

mattstuhring commented Dec 8, 2022 β€’

Excellent course! I appreciate that I can learn Typescript and NestJS in parallel.

@UmutSERIFLER
Copy link

It is so helpful course, thanks a lot

@imadueno
Copy link

amazing course πŸš€

@jtrejos506
Copy link

Great course! πŸš€

@alieslamifard
Copy link

Well done @arielweinberger πŸš€
Let me offer my two cents on how we can use class-validator to validate a password.

@IsStrongPassword({
    minLength: 8,
    minLowercase: 1,
    minNumbers: 1,
    minSymbols: 1,
    minUppercase: 1
})

The default error message is password is not strong enough

@johnsonsirv
Copy link

Well done @arielweinberger πŸš€ Let me offer my two cents on how we can use class-validator to validate a password.

@IsStrongPassword({
    minLength: 8,
    minLowercase: 1,
    minNumbers: 1,
    minSymbols: 1,
    minUppercase: 1
})

The default error message is password is not strong enough

Cool πŸš€ thanks for sharing too.

@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';

@belspirit
Copy link

@arielweinberger thank you for this great course!

@alieslamifard and @seunAwonugba thank you for your findings!

@Enzoreal100
Copy link

@arielweinberger just started on a job and they recommended me your course! It is awesome! Thanks!

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