title: Javascript Char Codes - Key Code 0
body: <p>I have an <code>input field</code> in <code>thymeleaf HTML</code> with number validation in <code>javascript</code>, according to my research, there is several ways, how to do it.</p>
  <p>One of them:</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 () {
        $("#quantity").keypress(function (e) {
           if (e.which != 8 &amp;&amp; e.which != 0 &amp;&amp; (e.which &lt; 48 || e.which &gt; 57)) {
              $("#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;</code></pre>
  </div>
  </div>
  </p>
  <p>The question: What is 0 in first if statement?</p>
  <p>According to <a href="https://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes" rel="nofollow noreferrer">this</a> key code 8 is backspace and numbers between 48 - 57 are numbers (i.e.: 1,2,3,...,9).</p>