如何仅使用PrimeFaces inputMask元素将输入限制为可变数量的数字 [英] How to restrict an input to a variable amount of numbers only with PrimeFaces inputMask element

查看:82
本文介绍了如何仅使用PrimeFaces inputMask元素将输入限制为可变数量的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要定义与此正则表达式类似的内容:

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( 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆