Is there any way of writing an inputText which is only accepting digits and also in the #,###.00 pattern format for inputting a currency number in JSF ? (using PrimeFaces will be more appreciated)
Thanks...
Is there any way of writing an inputText which is only accepting digits and also in the #,###.00 pattern format for inputting a currency number in JSF ? (using PrimeFaces will be more appreciated)
Thanks...
 
    
     
    
    Check this link
Here says you can use:
<p:inputMask value="# {maskController.date}" mask="99/99/9999"/>
I never used PrimeFaces before but i've used JSF. If you dont want to use javascript, you need to use a convert tag inside of the inputText tag.
<h:inputText id="money" required="true">
<f:convertNumber maxFractionDigits="2"
    groupingUsed="true"
    currencySymbol="$"
    maxIntegerDigits="4"
    type="currency"/>
</h:inputText>
PD: RegEx is another option. RegEx means Regular Expression. It is a way to check if something like an string matches with a rule. You can use in jsf with the RegEx Validator.
 
    
    This below code is working
<script>
<![CDATA[
function isNumber(event) {
  if (event) {
    var charCode = (event.which) ? event.which : event.keyCode;
    if (charCode < 48 || charCode > 57) 
       return false;
  }
  return true;
}
]]>
</script>
<p:inputText id="money" onkeydown="return isNumber(event);" />
to erase key available
<script>
<![CDATA[
function isNumber(event) {
  if (event) {
    var charCode = (event.which) ? event.which : event.keyCode;
    if ((charCode < 48 || charCode > 57) &&  charCode!=8 && charCode!=46) 
       return false;
  }
  return true;
}
]]>
</script>
<p:inputText id="money" onkeydown="return isNumber(event);" />
 
    
    Adding additional helpful not listed answer for this question :
Simply you can use primefaces extension tag inputNumber : 
https://www.primefaces.org/showcase/ui/input/inputNumber.xhtml
 
    
    