Created
May 15, 2015 13:06
-
-
Save egulhan/1247095a9ccc61596a1d to your computer and use it in GitHub Desktop.
Jquery plugin for only numeric input
This file contains hidden or 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
| /* Only number input fields */ | |
| jQuery.fn.ForceNumericOnly = | |
| function() | |
| { | |
| return this.each(function() | |
| { | |
| $(this).keydown(function(e) | |
| { | |
| var key = e.charCode || e.keyCode || 0; | |
| // allow backspace, tab, delete, enter, arrows, numbers and keypad numbers ONLY | |
| // home, end, period, and numpad decimal | |
| return ( | |
| key == 8 || | |
| key == 9 || | |
| key == 13 || | |
| key == 46 || | |
| key == 110 || | |
| key == 190 || | |
| (key >= 35 && key <= 40) || | |
| (key >= 48 && key <= 57) || | |
| (key >= 96 && key <= 105)); | |
| }); | |
| }); | |
| }; | |
| $(".onlynumeric").ForceNumericOnly(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment