Created
June 27, 2017 12:58
-
-
Save maxcelos/b03aec4536bcb7786de843cbf96389d4 to your computer and use it in GitHub Desktop.
Only numbers JQuery class mask
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
// 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