0    function CheckPassword() {
        var temp = document.getElementById('<%=Password_TextBox.ClientID %>').value;
        if (CheckStr(temp ,6,16)){
            alert('抱歉!密码字母和数字组合!');
            return false;
        }
        else {
            //alert("是");
            return true;
        }
    }
    function CheckStr(str, s, e)
    {
        var m = eval("/^[a-zA-Z0-9_\-]{" + s + "," + e + "}$/");
        return m.test(trim(str));    }
    function trim(s)
    {
        return s.replace(/\s/g, "");
    }为什么检测的不准确,哪里错了?

解决方案 »

  1.   

    <asp:TextBox ID="Password_TextBox" runat="server" Width="272px" TextMode="Password" MaxLength="16"  ></asp:TextBox>cs文件添加:
    this.Password_TextBox.Attributes.Add("onblur", "CheckPassword()");
      

  2.   

    <script>
     function CheckPassword() { 
            var temp = document.getElementById(' <%=Password_TextBox.ClientID %>').value; 
            if (CheckStr(temp ,6,16)){ 
                alert('抱歉!密码字母和数字组合!'); 
                return false; 
            } 
            else { 
                //alert("是"); 
                return true; 
            } 
        } 
        function CheckStr(str, s, e) 
        { 
            var m = eval("/^[a-zA-Z0-9_\-]{" + s + "," + e + "}$/"); 
            return m.test(trim(str));     } 
        function trim(s) 
        { 
            return s.replace(/\s/g, ""); 
        } 
    </script>
    cs文件添加: 
    this.Password_TextBox.Attributes.Add("onblur", "CheckPassword()"); 
      

  3.   

    <asp:TextBox ID="Password_TextBox" runat="server" Width="272px" TextMode="Password" MaxLength="16"  > </asp:TextBox> 
    <script> 
    function CheckPassword() { 
            var temp = document.getElementById(' <%=Password_TextBox.ClientID %>').value; 
            if (CheckStr(temp ,6,16)){ 
                alert('抱歉!密码字母和数字组合!'); 
                return false; 
            } 
            else { 
                //alert("是"); 
                return true; 
            } 
        } 
        function CheckStr(str, s, e) 
        { 
            var m = eval("/^[a-zA-Z0-9_\-]{" + s + "," + e + "}$/"); 
            return m.test(trim(str));     } 
        function trim(s) 
        { 
            return s.replace(/\s/g, ""); 
        } 
    </script> 
    cs文件添加: 
    this.Password_TextBox.Attributes.Add("onblur", "CheckPassword()"); 
      

  4.   

    正则没问题,是你用错了if (CheckStr(temp ,6,16)){ ===>   if (!CheckStr(temp ,6,16)){