0

I have a field in JSF2, I tried execute a validation in this way:

<h:inputText value="#{manutencaoContratoBean.contrato.nuContrato}" style="text-align: left; width: 90%; ">
<f:convertNumber pattern="#######" maxFractionDigits="0" maxIntegerDigits="16"/>

And thus:

<h:inputText value="#{manutencaoContratoBean.contrato.nuContrato}" style="text-align: left; width: 90%; ">
  <f:convertNumber integerOnly="true"/

However, my field only makes a validation and show me a message, I would like just the insertion of numbers, not Strings, this is possible ?

Is possible a insertion only of numbers ? I'm using RichFaces 4, if that's relevant.

I found this, it´s work well:

onkeypress="if(event.which &lt; 48 || event.which &gt; 57) return false;"

But this not allow a click on the backspace button, in case the user make a mistake.

Thanks in advance for all !

Edson Cezar
  • 25,884
  • 5
  • 19
  • 27

1 Answers1

3

I finished using this function:

onkeypress="if(event.which &lt; 48 || event.which &gt; 57 ) if(event.which != 8) return false;"

This work well in IE and Chrome, I don´t know why it´s not work well in firefox too, this function block the tab key in Firefox.

For the tab key work fine in firefox add this:

onkeypress="if(event.which &lt; 48 || event.which &gt; 57 ) if(event.which != 8) if(e.keyCode != 9) return false;"

Thanks for all.

Edson Cezar
  • 25,884
  • 5
  • 19
  • 27