Reputation: 21
I need to restrict the inputtext using onkeypress event to allow only numbers and decimal. i am able to restrict numbers but its not allowing dot value.
<h:inputText value="#{dimStackLine.max}"
onkeypress="if( (event.which < 48 || event.which > 57) ) return false;">
<p:ajax event="change" process="@this"></p:ajax>
<f:convertNumber pattern="####0.00000" />
</h:inputText>
Upvotes: 0
Views: 874
Reputation: 6184
Input of decimal dot .
is prevented by your onkeypress
because the event key code is 46 which is not within the allowed range of 48 <= code <= 57
. You have to allow code 46 additionally:
<h:inputText value="#{dimStackLine.max}"
onkeypress="if( (event.which < 48 || event.which > 57) && event.which != 46 ) return false;">
<p:ajax event="change" process="@this"></p:ajax>
<f:convertNumber pattern="####0.00000" />
</h:inputText>
Upvotes: 2