5

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...

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Faruk Postacioglu
  • 133
  • 1
  • 2
  • 17

3 Answers3

4

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.

tomiito
  • 61
  • 1
  • 3
1

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);" />
Ömer Faruk Kurt
  • 500
  • 3
  • 14
1

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

Marc Bouvier
  • 642
  • 1
  • 11
  • 27
Al-Mothafar
  • 7,949
  • 7
  • 68
  • 102