Last active
September 15, 2016 16:02
-
-
Save kdarty/b8735c49119f3825296c5e451731a91a to your computer and use it in GitHub Desktop.
While Input Type TEXT can easily be limited to input based on the Maxlength, Input Type NUMBER does not. To fix this shortcoming and keep the user-friendly experience of moving to a Numeric Keyboard on Mobile, trap the "KeyUp" Event and slice input text based on the given Maxlength of the field.
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
// On Key Up Event Handler to ensure Numeric Inputs adhere to their Max Length | |
$('input[type=number]').on('keyup', function (event) { | |
var maxlength = $(this).attr('maxlength'); | |
if (this.value.length > maxlength) { | |
this.value = this.value.slice(0, maxlength); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment