簡體   English   中英

如何將Primefaces inputMask限制為數字並激活復制和粘貼

[英]How to restrict Primefaces inputMask to number and activate the copy and paste

我只需要將p:inputMask限制為數字,並且還需要激活復制和粘貼,這是我的代碼:

<p:inputMask maxlength="18" id="numeroDocumento"
   name="numeroDocumento" label="Número de documento"
   value="#{dtConsultarInfController.numeroDocumento}"
   title="#{pmsg['sif.screen.consultarVerificarInf.label.docNumber']}">
   <p:keyFilter regEx="/[\d]/" />
</p:inputMask>
<p:keyFilter for="numeroDocumento" mask="num" preventPaste="false" />

有人可以幫我嗎?

我已經在您的代碼中添加了“ onkeypress”,請立即嘗試操作,通常它將只能將輸入內容限制為數字:

<p:inputMask maxlength="18" id="numeroDocumento"
 name="numeroDocumento" label="Número de documento"
 <p:inputMask maxlength="18" id="numeroDocumento"
  name="numeroDocumento" label="Número de documento"
    onkeypress="if((event.which &lt; 48 &amp;&amp; event.which != 46 
    &amp;&amp; event.which != 8) || event.which &gt; 57) return false;">
  value="#{dtConsultarInfController.numeroDocumento}"
  title="#{pmsg['sif.screen.consultarVerificarInf.label.docNumber']}">
  <p:keyFilter regEx="/[\d]/" />
</p:inputMask>
<p:keyFilter for="numeroDocumento" mask="num" preventPaste="false" />
  value="#{dtConsultarInfController.numeroDocumento}"
  title="#{pmsg['sif.screen.consultarVerificarInf.label.docNumber']}">
  <p:keyFilter regEx="/[\d]/" />

非常感謝我的朋友,您的解決方案允許購買點號。我已更改onkeypress屬性的條件,並且運行成功!

這是解決方案:

<p:inputMask maxlength="18" id="numeroDocumento"
name="numeroDocumento" label="Número de documento"
onkeypress="if((event.which &lt; 48 &amp;&amp; event.which != 8) || event.which &gt; 57) return false;" value="# dtConsultarInfController.numeroDocumento}"     title="#{pmsg['sif.screen.consultarVerificarInf.label.docNumber']}"></p:inputMask><p:keyFilter for="numeroDocumento" mask="num"preventPaste="false" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM