Created
March 15, 2014 04:09
-
-
Save jphase/9561722 to your computer and use it in GitHub Desktop.
Force numeric input with cmd and ctrl actions
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
// Force numeric only input | |
$.fn.numeric = function() { | |
return this.each(function() { | |
$(this).keydown(function(e) { | |
var key = e.charCode || e.keyCode || 0; | |
// Allow backspace, tab, delete, arrows, numbers, keypad numbers, home, end, period, cmd + a, cmd + r, ctrl + a, ctrl + r, and numpad decimal ONLY | |
return (key == 8 || key == 9 || key == 46 || key == 110 || key == 190 || (key >= 35 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105) || (key == 65 && e.ctrlKey === true) || (key == 82 && e.ctrlKey === true) || (key == 65 && e.metaKey === true) || (key == 82 && e.metaKey === true)); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment