HTML5的input中的pattern如何限定给定字符的个数?
高洛峰
高洛峰 2017-04-17 11:37:42
0
3
957

例如
我需要限制输入为一到三位数
我现在用的是

pattern="[0-9]?[0-9]?[0-9]?"

我看可以

pattern= "[0-9]{3}"

来指定匹配三位数
也可以

"[0-9]+"
"[0-9]*"

那么有没有指定匹配m-n个数字的方法呢?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(3)
小葫芦

{m,n} This should be fine

<form action="#" method="get">
    <input type="text" name="country_code" pattern="[0-9]{1,3}" title="请输入1至3个数字" />
    <input type="submit" />
</form>
阿神
[0-9]{3,5}
Peter_Zhu

The

pattern attribute is mainly used to verify whether the content you input is consistent with the content of your abbreviated regular expression. If they are inconsistent, the browser's built-in form plug-in will give appropriate prompts.

The

input tag can use maxlength to limit the maximum number of digits. The minimum number of digits has no attribute to control it.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template