Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write an inputText accepting only integers in the #,###.00 pattern

Tags:

jsf

primefaces

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

like image 577
Faruk Postacioglu Avatar asked Nov 30 '11 15:11

Faruk Postacioglu


People also ask

How do you make an input field only accept numbers?

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.

How do you input numbers only in HTML?

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.

How do you make input only accept numbers in Python?

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.


1 Answers

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.

like image 144
tomiito Avatar answered Oct 23 '22 07:10

tomiito