Last active
May 30, 2018 08:27
-
-
Save suebphatt/b4a4516e574553de823bdb399de9756e to your computer and use it in GitHub Desktop.
ONLY NUMBER JS -- Allow only number to be typed on input field, also works on mobile
This file contains 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
// -- number only 2 | |
$(".only-number").on('keyup change', function(){ | |
// Remove invalid characters | |
var sanitized = $(this).val().toString().replace(/[^0-9]/g, ''); | |
// Update value | |
$(this).val(sanitized); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment