Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Sanix-Darker/516c7fbd996a9bb4cc3b47828b5e5609 to your computer and use it in GitHub Desktop.

Select an option

Save Sanix-Darker/516c7fbd996a9bb4cc3b47828b5e5609 to your computer and use it in GitHub Desktop.
[HTML][JS] Accept only number in input type text
<input type="text" class="form-control" onkeypress="return isNumber(event)">
<script>
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;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment