Skip to content

Instantly share code, notes, and snippets.

@imzjy
Last active August 29, 2015 14:21
Show Gist options
  • Save imzjy/e60eccdd385fa2b75381 to your computer and use it in GitHub Desktop.
Save imzjy/e60eccdd385fa2b75381 to your computer and use it in GitHub Desktop.
javascript and jquery snippets, utils, etc.
//only numberic input
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 == 86 && (ctrlKey||metaKey)) || //ctrl+v=>copy
key == 8 ||
key == 9 ||
key == 13 ||
key == 46 ||
key == 110 ||
key == 190 ||
(key >= 35 && key <= 40) ||
(key >= 48 && key <= 57) ||
(key >= 96 && key <= 105));
});
});
};
$("#day").ForceNumericOnly();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment