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