当我把数字放在我的“密码”中时,没有大写的错误信息。帮帮我!!!您可以忽略大部分代码。我的问题是为什么当我把数字放在密码中时,控制台不会记录“不正确的密码,请输入一个大写字母。” (你输入密码的地方在代码的最后一行)谢谢你的帮助!为什么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