如何确保在HTML中使用pattern属性输入7到10位数字?我有以下代码:
<input type="number" name="Student" id="studID" required pattern="\d{7,10}" />
number
类型的输入元素不支持pattern
属性:请参阅<input type="number">
中的MDN文档
除了所有类型通常支持的属性外,类型编号的输入还支持以下属性:
Attribute Description max The maximum value to accept for this input min The minimum value to accept for this input placeholder An example value to display inside the field when it's empty readonly A Boolean attribute controlling whether or not the value is read-only step A stepping interval to use when using up and down arrows to adjust the value, as well as for validation
<input type="text">
具有pattern属性。
您可以像这样使用min
和max
属性。
<input type="number" name="Student" id="studID" min="1000000" max="9999999999">
<input type="number" name="Student" id="studID" minlength="7" maxlength="10">
应该解决你遇到的问题
您可以像这样添加模式属性:
<input type="number" name="Student" id="studID" required pattern="7-10" />