如何将Primefaces inputMask限制为仅数字? [英] How to restrict Primefaces inputMask to numbers only?

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

问题描述

我想将p:inputMask限制为仅 个数字,我从以下位置尝试了建议的解决方案:

I want to restrict p:inputMask to numbers only, and I tried the proposed solutions from:

但是他们都不起作用.我尝试了以下两种方法:

But none of them worked. I tried these two ways:

<p:inputMask id="userNo"  maxlength="2" mask="9?9999" />

<p:inputMask id="userNo"  maxlength="2" >
    <pe:keyFilter regEx="/[0-9_]/i"/>
</p:inputMask>

推荐答案

我认为这种方法是正确的,但我注意到您没有在inputMask上放置value属性. 你会试穿吗?

I think that approach is right but I noticed that you don't put value attribute on inputMask. Do you try to put it on?

这些解决方案有效:

These solutions works:

inputMaskTest.xhtml:

<h3>Input Mask:</h3>
<h:form id="form">
    <p:outputLabel value="Input Mask only number " for="userNo1" />
    <p:inputMask id="userNo1"  maxlength="2" mask="9?9999" value="#{inputMaskView.number}"/>

    <p:outputLabel value="Input Mask only Number Primeface Ext " for="userNo2" />
    <p:inputMask id="userNo2" maxlength="2" value="#{inputMaskView.number}">
        <pe:keyFilter regEx="/[0-9_]/i" />
    </p:inputMask>
</h:form>

InputMaskView.java:

@ManagedBean(name = "inputMaskView")
@ViewScoped 
public class InputMaskView {
  private String number;

  public String getNumber() {
    return number;
  }
  public void setNumber(String number) {
    this.number = number;
  }
}

  • 另请参见: http://forum.primefaces.org/viewtopic .php?f = 3& t = 37665
    • see also: http://forum.primefaces.org/viewtopic.php?f=3&t=37665
    • 这篇关于如何将Primefaces inputMask限制为仅数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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