title: Javascript restrict text field to numbers and decimals?
body: <p>I've tried a few solutions here but all of them boil down to removing the non-numeric input after the input is put in. </p>
  
  <p>This solution here works for numbers:
  <a href="https://jsfiddle.net/HkEuf/17470/" rel="nofollow noreferrer">https://jsfiddle.net/HkEuf/17470/</a></p>
  
  <p>But it doesn't allow decimals. </p>
  
  <p>I've to edit it as follows but it still won't allow for decimals:</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>    $(document).ready(function () {
        //called when key is pressed in textbox
      
            $("#quantity").keypress(function (e) {
               //if the letter is not digit then display error and don't type anything
               if (e.which != 110 &amp;&amp; e.which != 190 &amp;&amp; e.which != 8 &amp;&amp; e.which != 0 &amp;&amp; (e.which &lt; 48 || e.which &gt; 57 )) {
                  //display error message
                  $("#errmsg").html("Digits Only").show().fadeOut("slow");
                         return false;
              }
             });
          });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;input type="text" name="quantity" id="quantity" /&gt;</code></pre>
  </div>
  </div>
  </p>