Skip to content

Instantly share code, notes, and snippets.

@Awilum
Created December 26, 2012 10:13
Show Gist options
  • Save Awilum/4379409 to your computer and use it in GitHub Desktop.
Save Awilum/4379409 to your computer and use it in GitHub Desktop.
Usage: $('.phone').numeric();
// Numeric plugin
(function($) {
$.fn.numeric = function() {
return this.each(function() {
$(this).keydown(function(e) {
var key = e.charCode || e.keyCode || 0;
return (key == 8 || key == 9 || key == 46 || (key >= 35 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105));
});
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment