对于这个家庭作业,我必须编写代码来检查下面显示的用户名是否有效,但是如果前两个警报存在,最后一个警报会如何显示?
function isUserNameValid(user) {
"use strict";
var alert = "";
if (user.length > 12) {
alert("cannot be more than 12 letters long");
return false;
}
alert = /^[A-Za-z]+$/;
if (!alert.test(user)) {
alert("must only use letters A-Z or a-z");
return false;
}
alert = /^[A-Za-z]+$/; //<--(this part is the question?)
if(user.length > 12 || if(!alert.test(user)) {
alert("must only use letters A-Z or a-z and cannot be more than 12 letters long)";
return false;
}
return true;
}
答案 0 :(得分:0)
如果在下面和之后的其余两个
之后放第一个if(user.length > 12 && if(!a.test(user)) {
alert("must only use letters A-Z or a-z and cannot be more than 12 letters long)"; return false;
}