Skip to content

Instantly share code, notes, and snippets.

@caseymhunt
Created July 3, 2013 17:48
Show Gist options
  • Select an option

  • Save caseymhunt/5920945 to your computer and use it in GitHub Desktop.

Select an option

Save caseymhunt/5920945 to your computer and use it in GitHub Desktop.
JS & jQuery script that only allows numbers in a specified text field based on vanilla JS key mappings(code): http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
$('#elementID').keydown(function (event) {
if (event.keyCode > 57) {
if (event.keyCode < 96 || event.keyCode > 105) {
event.preventDefault();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment