Skip to content

Instantly share code, notes, and snippets.

@ikushaldave
Forked from HarishChaudhari/passwordRegex.js
Created February 12, 2021 16:44
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 ikushaldave/e356d7c0e6a53de37be55a4969cced94 to your computer and use it in GitHub Desktop.
Save ikushaldave/e356d7c0e6a53de37be55a4969cced94 to your computer and use it in GitHub Desktop.
Password validation RegEx for JavaScript
/**
* Password validation RegEx for JavaScript
*
* Passwords must be
* - At least 8 characters long, max length anything
* - Include at least 1 lowercase letter
* - 1 capital letter
* - 1 number
* - 1 special character => !@#$%^&*
*
* @author Harish Chaudhari <harishchaudhari.com>
*
*/
var str = "password"; // your password field's value goes here
/^(?=.*[\d])(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*])[\w!@#$%^&*]{8,}$/.test(str);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment