Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 views
in Technique[技术] by (71.8m points)

html - 如何设置密码的最小长度(How to set minimum length of password)

I am currently working on a html form.

(我目前正在处理html表单。)

How do I set the minimum length of the password to 8 so that it will reject any password the user inputs that are less than 8. How to do this?

(如何将密码的最小长度设置为8,以便它将拒绝用户输入的少于8的任何密码。如何执行此操作?)

Here is the code:

(这是代码:)

<div id="login-form">
            <form method="post">
            <table align="center" width="30%" border="0">
            <tr>
            <td><input type="text" name="email" placeholder="Your Email" required /></td>
            </tr>
            <tr>
            <td><input type="password" name="pass" placeholder="Your Password" required /></td>
            </tr>
            <tr>
            <td><button type="submit" name="btn-login">Sign In</button></td>
            </tr>
            <tr>
            <td><a href="register.php">Sign Up Here</a></td>
            </tr>
            </table>
            </form>
        </div>
  ask by marse translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you are using HTML5 you can use the pattern and required attributes for the input tag:

(如果您使用的是HTML5,则可以为input标签使用模式和必需的属性:)

<input type="password" pattern=".{8,}"   required title="8 characters minimum">
<input type="password" pattern=".{8,12}" required title="8 to 12 characters">

Also there is a minlength attribute for input tags but it does not work in some browsers :

(输入标签也有一个minlength属性,但在某些浏览器中不起作用:)

<input type="password" minlength="8" required>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...