如何仅使用PrimeFaces inputMask元素将输入限制为可变数量的数字 [英] How to restrict an input to a variable amount of numbers only with PrimeFaces inputMask element
问题描述
我需要定义与此正则表达式类似的内容:
I need to define something similar to this regex:
[0-9]{1, 5}
在PrimeFaces <inputMask>
元素上:
On a PrimeFaces <inputMask>
element:
<p:inputMask mask="regexGoesHere" value="#{someBean.val}"/>
我看了看PrimeFaces展示柜,但是我不知道该怎么做.
I looked at the PrimeFaces showcase, but I couldn't figure out how to do it.
那么除了JavaScript之外,还有谁知道怎么做吗?
So does anyone know how to do it in any way besides JavaScript ?
我并不是完全想用<inputMask>
寻找解决方案,但可以阻止我在客户端输入中键入字母的任何内容都是可以的.
I'm not exactly looking for a solution with <inputMask>
anything that would restrict me from typing letters in the input on the client side is OK.
谢谢
推荐答案
如果您也希望或也需要限制长度,可以执行以下操作:
If you want or need to limit the length too, you could do something like this:
<p:inputMask
mask="9?9999"
maxlength="5"
slotChar=" "
value="#{someBean.val}" />
用户只能输入1到5位数字,以下只能输入4位数字,依此类推
where the user can only enter 1 to 5 digits, or the following for four digits and so on
<p:inputMask
mask="9?999"
maxlength="4"
slotChar=" "
value="#{someBean.val}" />
PrimeFaces 5.1之前的版本:使用placeHolder
代替slotChar
(
查看全文