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...
By default, HTML 5 input field has attribute type=”number” that is used to get input in numeric format. Now forcing input field type=”text” to accept numeric values only by using Javascript or jQuery. You can also set type=”tel” attribute in the input field that will popup numeric keyboard on mobile devices.
The <input type="number"> defines a field for entering a number. Use the following attributes to specify restrictions: max - specifies the maximum value allowed. min - specifies the minimum value allowed.
To only accept numbers as user input: Use a while True loop to loop until the user enters a number. Use the float() class to attempt to convert the value to a floating-point number. If the user entered a number, use the break statement to break out of the loop.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With