JavaScript Tutorial Password Validator
The following check function, the password field is blank, only allow letters and numbers-this time no underscopes. Therefore, we should use a new regular expression to prohibit underscopes. These 1/[w_]/Only allow letters and numbers. Next, we want to allow at least 1 passwords to contain letters and numbers. To do this, we use the SEACRH () method and two regular expressions:/(Arizona, State) +/And/(0-9)/.
function ValidatePassword (FLD) {
var error = "";
var illegalchars =/[w_]/; Allow only letters and numbers
if (Fld.value = = "") {
Fld.style.background = ' yellow ';
Error = "You didn ' t enter a PASSWORD.N";
else if ((Fld.value.length < 7) | | (Fld.value.length > 15)) {
Error = "The password is the wrong length. n ";
Fld.style.background = ' yellow ';
else if (Illegalchars.test (Fld.value)) {
Error = "The password contains illegal CHARACTERS.N";
Fld.style.background = ' yellow ';
Or else if (! (Fld.value.search ((A-Z) +/)) && (Fld.value.search (/(0-9) +/))) {
Error = "The password must contain at least one NUMERAL.N";
Fld.style.background = ' yellow ';
} else {
Fld.style.background = ' white ';
}
return error;
}