本帖最后由 zhangwlkw 于 2012-12-21 16:56:08 编辑

解决方案 »

  1.   


    var validatePasswd = function(value) {
    var msg = "";
    msg = /^[a-zA-Z0-9]{8}$/.test(value) ? msg : "密码包含数字,字母; 并且必须是八位; ";
    msg += /[A-Z]/g.test(value) ? "" : "其中大写字母必须有.";
    if(msg) { alert(msg); }
    }
      

  2.   

    长度length就可以判断判断大写:
    if(/^[A-Z]+$/.test("DDD") )
    {
    alert('全是大写');
    }else{
    alert('不全是');
    }
      

  3.   

    <input type="text" onblur="check(this)" maxlength="8" />
    <script type="text/javascript">
      function check(obj){
          var v=obj.value;
          if(v!=""){
              if(!/\d+/g.test(v)){
                  alert("必须含有数字");
              }else if(!/[A-Z]+/g.test(v)){
                  alert("必须含有大写字母");
              }else if(v.length!=8){
                  alert("必须是8位数");
              }
          }
      }
    </script>