title: Limit the amount of digits allowed in a Number Input javascript
body: <p>I have a number input: <code>&lt;input type = 'number&gt;</code>, and I needed to know how to limit the amount of integers that you could insert into the input</p>
  <p>So I came up with what's in the snippet, but are there any other solutions that may be faster to implement, or just better in general.</p>
  <p>This question has a similar answer, but I am trying to scour the internet to see if there is a better answer to it.</p>
  <p><a href="https://stackoverflow.com/questions/8354975/how-can-i-limit-possible-inputs-in-a-html5-number-element">Similar Question</a></p>
  <p>EDIT: I have found the answer that works to it, and I am looking for something of a one liner that would work. Something like the <code>max = '4'</code> or the input's version of it <code>maxlength = '4'</code></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const Input  = document.getElementById('input')
  
  function limitDigits(element, amount) {
    element.addEventListener('input', () =&gt; {
      if (element.value.length &gt; amount) {
          element.value = Math.floor(element.value/10)
        } 
    }) 
  }
   
  limitDigits(Input, 4)</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>input[type="number"]::-webkit-outer-spin-button,
  input[type="number"]::-webkit-inner-spin-button {
      -webkit-appearance: none;
      margin: 0;
  }
  #input {
    width:30px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input id = 'input' type = 'number'&gt;</code></pre>
  </div>
  </div>
  </p>