Skip to content

Instantly share code, notes, and snippets.

@kladov
Last active September 28, 2018 08:26
Show Gist options
  • Save kladov/3e41c5b174bdd1e1dff2 to your computer and use it in GitHub Desktop.
Save kladov/3e41c5b174bdd1e1dff2 to your computer and use it in GitHub Desktop.
set only number input
$(function(){
$('#some-element').on('keypress keydown', isNumber);
})
function isNumber(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 37 && charCode != 39 && charCode != 46) {
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment