对于这个作业,我必须编写代码来检查用户名是否有效,如下所示,但是如果前两个警报存在,最后一个警报会如何?
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;
}