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.
You can use a JS validation
First, you need to define a JS function to validate the input
Second, in your h:input, capture the onKeyPress event and call the function
And it will only let you enter numbers.
You can easily extend this use to other case when you need to validate whit other regex.
Note, this only work with key press, if you want to capture other user event, use the proper tag.
Cheers
This is working for me
Just bind the input value to a
Double
, or better,BigDecimal
property instead ofString
.JSF has builtin converters for those types which will kick in automatically. You can customize the converter message as below:
A html5, cross browser and client side solution could be
you need to reference a jquery resource if not implicitly available by e.g. prime faces