<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Test Password</title>
<SCRIPT LANGUAGE="JavaScript">
function validatePwd(fieldname) {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Copyright April 2004 Sani, A. I. (MCSE, MCSA, CCNA)
//sanijean@yahoo.co.uk
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Initialise variables
var errorMsg = "";
var space = " ";
fieldname = document.myform.password;
fieldvalue = fieldname.value;
fieldlength = fieldvalue.length;
//It must not contain a space
if (fieldvalue.indexOf(space) > -1) {
errorMsg += "\nPasswords cannot include a space.\n";
}
//It must contain at least one number character
if (!(fieldvalue.match(/\d/))) {
errorMsg += "\nStrong passwords must include at least one number.\n";
}
//It must start with at least one letter
if (!(fieldvalue.match(/^[a-zA-Z]+/))) {
errorMsg += "\nStrong passwords must start with at least one letter.\n";
}
//It must contain at least one upper case character
if (!(fieldvalue.match(/[A-Z]/))) {
errorMsg += "\nStrong passwords must include at least one uppercase letter.\n";
}
//It must contain at least one lower case character
if (!(fieldvalue.match(/[a-z]/))) {
errorMsg += "\nStrong passwords must include one or more lowercase letters.\n";
}
//It must contain at least one special character
if (!(fieldvalue.match(/\W+/))) {
errorMsg += "\nStrong passwords must include at least one special character - #,@,%,!\n";
}
//It must be at least 7 characters long.
if (!(fieldlength >= 7)) {
errorMsg += "\nStrong passwords must be at least 7 characters long.\n";
}
//If there is aproblem with the form then display an error
if (errorMsg != ""){
msg = "______________________________________________________\n\n";
msg += "Please correct the problem(s) with your trial password test it again.\n";
msg += "______________________________________________________\n";
errorMsg += alert(msg + errorMsg + "\n\n");
fieldname.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form name="myform" onSubmit="return validatePwd('password')">
<p>
<INPUT NAME="password" SIZE=30>
</p>
<P>
<INPUT TYPE="submit" value="Test">
</body>
</html>