设置最小密码长度

时间:2013-07-01 10:01:29

标签: php html internet-explorer passwords

我正在尝试为登录页面设置最小密码长度;但是,密码(输入)标签的唯一属性似乎是maxlength。我知道你可以使用新的模式或min属性,但是我需要一些在IE 9中有效的东西。有没有简单/替代方法来解决这个问题,还是我必须使用strlen?

5 个答案:

答案 0 :(得分:5)

到目前为止,答案还不错。

然而,这比客户端更关注服务器端。我很难“破解”标记或Javascript以允许短密码。

你应该经常检查服务器端,以确保没有任何奇怪的事情发生。

总结一下:使用Javascript确保密码长度超过最小长度并重新检查服务器端以确保不以任何方式绕过jsfunction。

答案 1 :(得分:2)

一个班轮:

<input type="text" onKeyPress="return ( this.value.length < 10 );"/>

这可用于在Internet Explorer中实现maxlength,但您也应验证输入服务器端。

答案 2 :(得分:2)

您必须使用服务器端解决方案来解决此问题,因为您永远不知道用户是否启用了j ..

答案 3 :(得分:2)

来自another question的回答,试试这个:

<input pattern=".{3,}" required title="3 characters minimum">
<input pattern=".{5,10}" required title="5 to 10 characters">

答案 4 :(得分:1)

function CheckLength(name) {

            var password = document.getElementById(name).value;

            if (password.length < 4)

                alert('should have miniumum 4 chars');

        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <input type="password" id="txtpassword" name="txtpassword" />
    <input type="submit" name="txtSubmit" onclick="CheckLength('txtpassword') " />