首页 > 解决方案 > 输入标签中的这个模式属性指定密码长度不起作用?

问题描述

模式属性不起作用,我在下面包含了代码。它正在打印消息,但是当我输入 6 或 7 或 8 个字符时,它不接受。

<input type="password" pattern=".{5,12}" name="password" id="password" required title="Password must be 5 to 12 characters"/>

标签: html

解决方案


它适用于表单提交事件。查看文档以了解其工作原理:https ://www.w3schools.com/tags/att_input_pattern.asp

只是为了测试尝试单击下面代码段中的提交按钮。

<form>
  <label>Password must be 5 to 12 characters: 
    <input type="password" pattern=".{5,12}" name="password" id="password" required title="Password must be 5 to 12 characters"/>
  </label>
  <button type="submit">Submit</button>
<form>

根据https://caniuse.com/#feat=input-pattern,几乎所有浏览器都支持它。


推荐阅读