Skip to content

Instantly share code, notes, and snippets.

@rickslayer
Created September 13, 2018 22:47
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 rickslayer/808394073e421cc1bd16690ca0925b89 to your computer and use it in GitHub Desktop.
Save rickslayer/808394073e421cc1bd16690ca0925b89 to your computer and use it in GitHub Desktop.
Input number com maxlength
<p>Number Input</p>
<input type="number" id="el_number" min="1" max="99" maxlength="2" />
<style>
input{
width : 200px;
height: 30px;
}
</style>
<script>
let numb = document.getElementById("el_number");
numb.addEventListener('input', function(){
if(this.value.length > this.maxLength){
this.value = this.value.slice(0, this.maxLength);
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment