Created
April 29, 2016 17:46
-
-
Save ikarius6/d296e179f0bfef8347922bbd1037bfa2 to your computer and use it in GitHub Desktop.
A regex to validate passwords with at least a capital, a digit and of 8 length using positive lookahead
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<pre id="test"></pre> | |
<script> | |
/* | |
Password validation with regex by Mr.Jack (github.com/ikarius6) | |
At least 1 capital | |
At least 1 number | |
Minimum length of 8 characters | |
Demo: https://jsfiddle.net/h5sutweh/ | |
*/ | |
var pass_validation = /(?=.*\d)(?=.*[A-Z]).{8,}/ | |
var words = [ | |
"RPr:._eF%iut`oB", | |
"olmpWMZ>/4';E", | |
"_TLBg)Xs*i0?v77S", | |
"&\}MGN(IQ|sE", | |
"GQc9.q4CLpGI4S", | |
"Aue5]P/fXnatEF", | |
"gFX>U[SGDV", | |
"DFOnBXy", | |
"3gB$y_ko!Q", | |
"'6P$j.oL-*2hY", | |
"6!YG}S8[Hw", | |
"V4E[[GG2#,('aOC", | |
"CcPHEB6", | |
"B(\!oIW1g'm?k", | |
"vu.*C_FyB&,W+", | |
"*{poZm1", | |
"`$*eOXpFVDBI;", | |
"!CoBwx@h9A-*Da}", | |
">51wZ|zf>''e", | |
"4I\G]2)n\ok*)x'S", | |
"q)UgC#!KX~\QAW", | |
":c3@{*|Aw,eC", | |
"&k>J/-y]!.`6dmek", | |
"V?hYeUinetE7", | |
"d!P7FVO*!", | |
"[8E!hY86*Vf", | |
":,DuW2+BYI", | |
"_TfJMlLm8", | |
"jX]bMj#.{]", | |
"ajjfl9]}.l;", | |
"Rdu20Won3tLb8", | |
"1']W*5@N$Jz", | |
"x1-6I}", | |
"nqK&F$h$(", | |
"scs4>Z.W{eF", | |
"twb?-A|@'Hd7", | |
"aJJg&T9K.s", | |
"hY/_25B^?S=kC`", | |
"-Ha,1Bz=7GO:#", | |
".}T{q3BxN&f", | |
"WC%2.46wUz?+Y", | |
"@?0c@&m+ob;tCR|", | |
"N3Z-UDF5k N5J~", | |
"V:U9YvWw", | |
"pG\}XUQ[{KE!Tq", | |
"$=nha^d/3F}}T", | |
"%ElR`5ss", | |
"m|J{K^|u-6E0", | |
"Q}4\I%R=fFvVv%", | |
"yv*Q$[x[", | |
]; | |
for(var i=0; i < words.length; i++){ | |
console.log( words[i].match( pass_validation ) ? 'yay!':'no' , words[i]); | |
var container = document.getElementById("test"); | |
container.innerHTML += (words[i].match( pass_validation ) ? 'yay':'no') + "\t" + words[i]+"<br/>"; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment