我试图使用以下代码:
<form>
<input pattern=".{5}|{10}">
<input type="submit" value="Check"></input>
</form>
似乎必须有某种方式让它发挥作用?
编辑澄清:我不想允许9,10,11,12,13。我想只允许8或14 谢谢, nb:因为原因,我无法使用Jquery Validation插件。
答案 0 :(得分:4)
您可以通过以下正则表达式模式指定它:
^.{8}$|^.{14}$
这就是您的代码的样子:
<form>
<input pattern="^.{8}$|^.{14}$">
<input type="submit" value="Check"></input>
</form>
铁路图:
说明强>
NODE EXPLANATION
----------------------------------------------------------------------
^ the beginning of a "line"
----------------------------------------------------------------------
.{8} any character except \n (8 times)
----------------------------------------------------------------------
$ before an optional \n, and the end of a
"line"
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
^ the beginning of a "line"
----------------------------------------------------------------------
.{14} any character except \n (14 times)
----------------------------------------------------------------------
$ before an optional \n, and the end of a
"line"
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
<强> Demo 强>
答案 1 :(得分:1)
管道后你错过了.
。
<input pattern=".{8}|.{14}">