我可以添加输入类型为数字的模式属性吗?

Can I add pattern attribute with input type as number?

这里我有一个HTML5输入.....

<input type="number" pattern="\d{10}" data-pattern-msg="enter a value according to the pattern" />

但这并没有验证这个模式...... 这是什么原因??

这是错误的 type = "number" 更改为 type="text" 并尝试

<input type="text" pattern="\d{10}" data-pattern-msg="enter a value according to the pattern" title="only number" />

定义和用法 pattern 属性指定用于检查元素值的正则表达式。

注意:模式属性适用于以下输入类型:文本、搜索、url、电话、电子邮件和密码。

提示:使用全局标题属性来描述模式以帮助用户。

W3C 的维护者 HTML Checker(验证器)在这里。检查器为您的示例发出错误的原因是 HTML 规范不允许为 <input type=number> 元素指定 pattern 属性;请参阅 以下内容属性不得指定且不适用于 the section on the HTML spec on <input type=number>Bookkeeping details 部分中的元素 列表。

而且我不确定大多数浏览器是否支持使用 placeholder<input type=number>