Here is the JavaScript code.
<html>
<head>
<title>Password validation</title>
<script language="javascript">
function CheckPassword()
{
var pw = pass.pw.value;
var cpw = pass.cpw.value;
if (pw != cpw) window.alert("Re-enter your password");
if (pw.length == 0)
{
alert("Please enter your password");
}
else if (pw.length < 3)
{
alert("Please enter aleast 3 characters password");
}
else if (pw == /^[A-Za-z]\w/)
{
alert("Your password first character must be a letter");
}
else if (pw == /^(?=.*[A-Z])/)
{
alert("Your password must contain atleast one uppercase letter");
}
else if (pw == /^(?=.*[a-z])/)
{
alert("Your password must contain atleast one uppercase letter");
}
else if (pw == /^(?=.*[0-9])/)
{
alert("Your password must contain atleast one numeric digit");
}
else if (pw == /^(?!.*\s)/)
{
alert("Your password must contain atleast one special character");
}
else window.alert("Your password is matched");
}
</script>
</head>
<center>
<body font size=5 bgcolor="lightgreen" leftmargin=50 topmargin=50 >
<Form id="pass" onSubmit="CheckPassword(this)" >
PASSWORD:
<input type=password name="pw"size=10 max length=8 ></input>
<br>
<br>
CONFIRM PASSWORD
<input type=password name="cpw"size=10 max length=8 ></input>
<br>
<br>
<br>
<input type="submit" name="sub" value="submit">
<input type="reset" name="rt" value="reset">
</center>
</body>
</html>
Thank you, keep learning and sharing
