Skip to content

Instantly share code, notes, and snippets.

@HarishChaudhari
Created August 1, 2016 13:29
Show Gist options
  • Save HarishChaudhari/0dd5514ce430991a1b1b8fa04e8b72a4 to your computer and use it in GitHub Desktop.
Save HarishChaudhari/0dd5514ce430991a1b1b8fa04e8b72a4 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);
@Durbois
Copy link

Durbois commented Jun 18, 2018

it works fine! thank you :)

@acalism
Copy link

acalism commented Aug 12, 2018

I think comma, semicolon and more ordinary symbols can be legal for a password.

@debaosuidecl
Copy link

AWESOME

@Syed47
Copy link

Syed47 commented Jan 29, 2019

very practical, thanks

@edsonromerop
Copy link

Thank you, it really works pretty well

@mernstackman
Copy link

What's the license?

@MaximeDauphinot
Copy link

Amazing ! thanks a lot

@kienltdev
Copy link

Thank you very much

@whege
Copy link

whege commented Feb 5, 2022

Sweet, thank you!

@KOUISAmine
Copy link

Amazing, works great, here is a demo

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