Created
October 3, 2017 09:01
-
-
Save Sanix-Darker/516c7fbd996a9bb4cc3b47828b5e5609 to your computer and use it in GitHub Desktop.
[HTML][JS] Accept only number in input type text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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