html – How to make a Spinner that only accepts numbers on PrimeFaces?


I'm using PrimeFaces for a college project. How do I get "Spinner" not to accept "Characters" only numbers?

<p:spinner id="spinnerBasic"  max="120" value="#{spinnerController.number1}"/>


Good afternoon, you can solve this problem using javascript as below:

<script type="text/javascript">
   function onlyNumbers(data){
      data.value = data.value.replace(/[^0-9]/g,'');

And in the spinner use ( you can change the call time if you want, using another type of event ):

<p:spinner id="spinnerBasic"  max="120" value="#{spinnerController.number1}" onkeyup="onlyNumbers(this)" />
Scroll to Top