我有一个要求密码字段应采用特定模式的地方
(#|#|#|#)
因此,我尝试了以下方法。
但是我没有任何输出
屏幕截图
javascript - 如何在HTML输入中获取模式-LMLPHP
如果有任何第三方库,请提供。我的方法



<input type="password" name="passwod" pattren="[0-9]{1}-[0-9]{1}-[0-9]{1}-[0-9]{1}" maxlength="4" /><br><br>

<label>Required input pattern</label>
<input type="text" name="sample" maxlength="7" value="#|#|#|#" />

最佳答案

a)更正您的错字:pattren应为pattern

b)maxlength应该为7(因为您要验证7个字符)。

c)(可选,但有用)将^$添加到模式正则表达式中,以表示所需匹配的开始和结束。



<input type="password" name="password" pattern="^[0-9]{1}-[0-9]{1}-[0-9]{1}-[0-9]{1}$" maxlength="7" /><br><br>

<label>Required input pattern</label>
<input type="text" name="sample" maxlength="7" value="#|#|#|#" />

10-05 21:04
查看更多