Created
September 13, 2018 22:47
-
-
Save rickslayer/808394073e421cc1bd16690ca0925b89 to your computer and use it in GitHub Desktop.
Input number com maxlength
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
<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