Primefaces Input for Money Input (exactly 2 digits after floating point)
13,631
A regular expression was the best way I've found so far
<p:inputText id="numInput" value="#{val.value}" required="true"
label="#{val.title}" validatorMessage="Not valid Number">
<p:ajax event="change" process="@form" update=":edit_main" />
<f:validateRegex pattern="^[-+]?[0-9]*\.?[0-9]{1,2}+$" />
</p:inputText>
<p:message for="numInput" />
Author by
yannicuLar
Bad code leads to anger. Anger leads to hate. Hate leads to suffering.
Updated on July 24, 2022Comments
-
yannicuLar almost 2 years
I need a PrimeFaces input component, to get/set an amount of cash, that means a Decimal with 2 digits after the floating point.
I tried using inputMask, like
<p:inputMask value="#{moneyBean.amount}" mask="999.99"/>
But I can't find some way to set a mask that accepts:
- 1 or more arithmetic values before floating point
- Optionally, a floating point "."
- 0 to 2 arithmetic values after the floating point
For Example, some valid inputs would be:
- 1234.56
- 1234.5
- 2.8
- 120
- 120.00
Any ideas to get this input in an efficient way?