Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created September 12, 2019 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreasvirkus/1facbfe6fb8f4cac0daea82f96d65fe7 to your computer and use it in GitHub Desktop.
Save andreasvirkus/1facbfe6fb8f4cac0daea82f96d65fe7 to your computer and use it in GitHub Desktop.
/**
* Medium-strength regex checks if the password contains 2 of:
* - lowercase alphabetical char
* - uppercase alphabetical char
* - numerical character
* - minimum of 6 characters
*
* Strong-strength regex checks if the password contains all of:
* - lowercase alphabetical char
* - uppercase alphabetical char
* - numerical character
* - minimum of 8 characters
* - a special character symbol
*/
export const mediumRegex = new RegExp('^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})')
export const strongRegex = new RegExp('^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{8,})')
export const passwordStrength = () => strongRegex.test(this.password)
? 2
: mediumRegex.test(this.password)
? 1
: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment