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



我需要按照以下要求验证密码:

至少 1 封信, 至少 1 个数字, 最少 6 个字符和最多 12 个字符, 不允许使用特殊字符。 这是我到目前为止所拥有的。

<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>

下面是解决您问题的正则表达式。

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

完整答案是:

<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>

最新更新