1

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

    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;
}
4

1 回答 1

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; 
}
于 2012-10-17T16:10:03.533 回答