title: How can I restrict decimal values from being entered in a input type="number"
body: <p>I have trouble restricting the input characters to integers only. Is there a way by which I can restrict the decimal numbers or float from being entered into the input type="<code>number</code>"?</p>
  
  <p>I have also tried the following approach by replacing <code>.</code> with <code>''</code> whenever event for <code>keyup</code> is fired:</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>$("#myForm").on('submit', function(e) {
    e.preventDefault();
  });
  
  $("#number").on('keyup', function() {
    var regex = new RegExp(/\d+\.\d?/g);
    var number = $(this).val();
    if (regex.test(number)) {
      number = number.replace(/\./g, '');
      $(this).val(number);
    }
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;form id="myForm" action="//google.de"&gt;
    &lt;p&gt;Input type number step 1&lt;/p&gt;
    &lt;input type="number" name="number" id="number" step="1" min="0"/&gt;
    &lt;input type="submit" /&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>With the above code, following are the case results:</p>
  
  <pre><code>WORKS:
  2.3
  
  FAILS:
  2..3
  2….3
  2.3.3.3.3.3.3.3.3.3.3.333...3
  </code></pre>
  
  <p>I need only 2 (any integer) to be allowed, and from all other cases (including the copy and paste), the decimal should be removed.</p>
  
  <p>So my final question is that how can I restrict float numbers from being entered in the input field with <code>type="number"</code>? If that's not possible then how can I change the above code to meet my requirements?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Please do not close this question if this question partially matches another. I have written a code here too. I want to know, what's wrong with it.</p>