Updated on Kisan Patel
This post will show you how to restrict the user to allow only numbers in input textbox using javascript.
script.js
function isNumber(evt) { evt = (evt) ? evt : window.event; var charCode = (evt.which) ? evt.which : evt.keyCode; if (charCode > 31 && (charCode < 48 || charCode > 57)) { return false; } return true; }
index.html
Enter Number: <input type="text" class="groupOfTexbox" onkeypress = "return isNumber(event)"/>
the output of the above example…
See the Pen jbGooo by Kisan (@pka246) on CodePen.