Skip to content

Instantly share code, notes, and snippets.

@dpmango
Created February 2, 2017 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpmango/678aaaf45480962e1c2b7dcda02522d7 to your computer and use it in GitHub Desktop.
Save dpmango/678aaaf45480962e1c2b7dcda02522d7 to your computer and use it in GitHub Desktop.
$(".ui-number input").keydown(function (e) {
if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
(e.keyCode === 65 && (e.ctrlKey === true || e.metaKey === true)) ||
(e.keyCode >= 35 && e.keyCode <= 40)) {
return;
}
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
e.preventDefault();
}
if ( $(this).val().length > 5 ){
e.preventDefault();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment