Created
July 24, 2013 10:21
-
-
Save csharpforevermore/6069449 to your computer and use it in GitHub Desktop.
Restrict the user to only being able to type a digit
This file contains 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').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