Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save csharpforevermore/6069449 to your computer and use it in GitHub Desktop.
Save csharpforevermore/6069449 to your computer and use it in GitHub Desktop.
Restrict the user to only being able to type a digit
$('input').bind('keypress', function (event) {
var regex = new RegExp("[\d]");
var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
if (!regex.test(key)) {
event.preventDefault();
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment