Skip to content

Instantly share code, notes, and snippets.

@maxcelos
Created June 27, 2017 12:58
Show Gist options
  • Save maxcelos/b03aec4536bcb7786de843cbf96389d4 to your computer and use it in GitHub Desktop.
Save maxcelos/b03aec4536bcb7786de843cbf96389d4 to your computer and use it in GitHub Desktop.
Only numbers JQuery class mask
// To use it, jus add the "numberInput" class on your input field
$('.numberInput').on('keypress', function (e) {
// Accept only numbers
var charCode = (e.which) ? e.which : e.keyCode;
if (charCode != 46 && charCode > 31
&& (charCode < 48 || charCode > 57))
return false;
}).on('keyup', function () {
$(this).val($(this).val().replace(/\D/g, ''));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment