首页 文章

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

提问于
浏览
0

我需要使用以下要求验证密码:

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

1 回答

  • 0

    以下是解决您问题的正则表达式 .

    ^(?=.*[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>
    

相关问题