Is there a way to confirm the value of an h:inputText
in JSF, which should accepts only digits. Means it can be an Integer
or the float
.
If I type 12s3a562.675
, a5678s12
, 68712haf.563345
or any other such kind of values, then it should show an error. Otherwise it accepts and proceeds.
Try this
<h:inputText onkeypress="if(event.which < 48 || event.which > 57) return false;"/>
is a short way if you want to accept integers only.It has the advantage over
type="number"
that you can't even enter a non-digitHere are some different options:
@Digits
from bean validation.<input type="number" />
I think that the best options are either using Bean validation, f:convertNumber or going with HTML5 as these are the cleanest and give you the least redundant code.
Instead of PrimeFaces Extension for you can use now!
https://www.primefaces.org/showcase/ui/input/inputNumber.xhtml
Try
If you add this to your xhtml
and use the inputext for numbers of Primefaces Extensions called pe:inputNumber , which not only validate your numbers but decimals also, may be more complete.