简体   繁体   English

HTML5输入模式验证字母和数字

[英]HTML5 input pattern validate letters and numbers

I need to validate password with these requirements: 我需要根据以下要求验证密码:

At least 1 Letter, At least 1 Number, Min 6 chars and Max 12 chars, Special characters not allowed. 至少1个字母,至少1个数字,最少6个字符和最多12个字符,不允许使用特殊字符。 Here's what I have so far. 到目前为止,这就是我所拥有的。

<form>
Password: <input type="password" name="pw" pattern="^(?=.*[a-zA-Z])(?=.*[0-9]).{6,12}$" title="Must contain at least one number and one letter, and at least 6 to 12 characters (special characters not allowed)">
<input type="submit">
</form>

Below is regex that solves your problem. 下面是解决您的问题的正则表达式。

^(?=.*[a-zA-Z])(?=\w*[0-9])\w{6,12}$

Full answer is: 完整答案是:

<form>
    Password: <input type="password" name="pw" pattern="^(?=.*[a-zA-Z])(?=\w*[0-9])\w{6,12}$" title="Must contain at least one number and one letter, and at least 6 to 12 characters (special characters not allowed)">
    <input type="submit">
</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM