當我把數字放在我的「密碼」中時,沒有大寫的錯誤信息。幫幫我!!!您可以忽略大部分代碼。我的問題是爲什麼當我把數字放在密碼中時,控制檯不會記錄「不正確的密碼,請輸入一個大寫字母。」 (你輸入密碼的地方在代碼的最後一行)謝謝你的幫助!爲什麼javascript的.toUpperCase函數包含數字?
var specialCharacters = ["!", "@", "#", "$", "%", "^", "&", "*", "(", ")",
"[", "]"];
function isPasswordValid(input) {
if (hasUpperCase(input) && hasLowercase(input) && isLongEnough(input) && hasSpecialCharacter(input)) {
console.log("The password is valid.");
}
if (!hasUpperCase(input)) {
console.log("Incorrect password. Please put a uppercase letter.");
}
if (!hasLowercase(input)) {
console.log("Incorrect password. Please put a lowercase letter.");
}
if (!isLongEnough(input)) {
console.log("Incorrect password. Please increase the length of your password to 8 characters.");
}
if (!hasSpecialCharacter(input)) {
console.log("Incorrect password. Please put a special character.");
}
}
function hasUpperCase(input) {
for (var i = 0; i < input.length; i++) {
if (input[i] === input[i].toUpperCase()) {
return true;
}
}
}
function hasLowercase(input) {
for (var i = 0; i < input.length; i++) {
if (input[i] === input[i].toLowerCase()) {
return true;
}
}
}
function isLongEnough(input) {
if (input.length >= 8) {
return true;
}
}
function hasSpecialCharacter(input) {
for (var i = 0; i < input.length; i++) {
for (var j = 0; j < specialCharacters.length; j++) {
if (input[i] === specialCharacters[j]) {
return true;
}
}
}
}
isPasswordValid("");
輸入可能是一個字符串,所以這個數字實際上是一個字符串。 – elclanrs