我需要使用以下要求验证密码:
至少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>
答案 0 :(得分:1)
以下是解决您问题的正则表达式。
^(?=.*[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>