首页 > HTML5的input中的pattern如何限定给定字符的个数?

HTML5的input中的pattern如何限定给定字符的个数?

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

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

我看可以

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

来指定匹配三位数
也可以

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

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


{m,n} 这样应该就可以吧

<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}
【热门文章】
【热门文章】