I am trying to write a regular expression to validate a password which must meet the following criteria:
I tried the following but it doesn't seem to work.
http://jsfiddle.net/many_tentacles/Hzuc9/
<input type='button' value='click' class='buttonClick' />
<input type='text' />
<div></div>
and...
$(".buttonClick").click(function () {
if ($("input[type=text]").filter(function () {
return this.value.match(/^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])([a-zA-Z0-9]{8})$/);
})) {
$("div").text("pass");
} else {
$("div").text("fail");
}
});
Any ideas?
Your regular expression should look like:
/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$/
Here is an explanation:
/^
(?=.*\d) // should contain at least one digit
(?=.*[a-z]) // should contain at least one lower case
(?=.*[A-Z]) // should contain at least one upper case
[a-zA-Z0-9]{8,} // should contain at least 8 from the mentioned characters
$/