「パスワード」に数字を入力すると、大文字のエラーメッセージは表示されません。助けて!!!ほとんどのコードを無視することができます。私の質問は、パスワードに数字を入れたときにコンソールに「パスワードが正しくありません。大文字を入れてください」というメッセージが表示されない理由です。 (パスワードの最後にはパスワードを入力しています)ありがとうございました!なぜ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