To ensure the password meets certain criteria, it must start with a Z
, have at least 8 characters, and contain an asterisk *
.
Take a look at this validating function:
function validatePassword()
{
var strPassword;
//Prompt user to enter password and validate
strPassword = prompt("Please Enter A Valid Password","");
while ((strPassword.length <7) || (strPassword.indexOf('*') ==-1) || (strPassword.charAt(0) != 'Z')) {
alert("Your password is invalid, \n Please try again");
strPassword = prompt("Please Enter A Valid Password","");
}
//Alert when password is valid
alert("Your password is valid");
//End while loop
}