Code Snippet
Password Strength
$('#pass').keyup(function(e) {
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var enoughRegex = new RegExp("(?=.{6,}).*", "g");
if (false == enoughRegex.test($(this).val())) {
$('#passstrength').html('More Characters');
} else if (strongRegex.test($(this).val())) {
$('#passstrength').className = 'ok';
$('#passstrength').html('Strong!');
} else if (mediumRegex.test($(this).val())) {
$('#passstrength').className = 'alert';
$('#passstrength').html('Medium!');
} else {
$('#passstrength').className = 'error';
$('#passstrength').html('Weak!');
}
return true;
});
Assumes this HTML:
<input type="password" name="pass" id="pass" />
<span id="passstrength"></span>
example please!
Just stick it into dreamweaver and run it! … or even Notepad :)
didn’t work !
Worked fine for me, and is a very good discerning script
@Amine : To get it working you just have to paste the code after the closing tag
Thanks for the snippet
Not work for me
how I put the js codes into html file?
This code snippet works great! Here is the simple code in action: http://jsfiddle.net/9SUWP/
must be use this js with above codes
script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js”>
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.