title: Set maximum number of words HTML textbox
body: <p>I want to set a <strong><em>maximum number</em></strong> of words the user can type in a textbox, <strong>not</strong> the number of character but <b>words</b>.
  <br>
  This is possible? <br> <br>
  I did some digging and found out how to get the number of words the user has inputted using regular expressions, but im not sure how to stop the user from entering more letters after reaching the max</p>
  
  <pre><code>var jobValue = document.getElementsById('textBox1').value
  var words = jobValue.value.match(/\S+/g).length;
  if(words&gt;=2){
     //stop inputs
  }
  </code></pre>
  
  <p>PS. <br>
  I want to limit the number of words to 2.</p>
  
  <h1>UPDATE</h1>
  
  <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>function wordLimit(){
      
         var jobValue = document.getElementById('wordIntent').value
         var words = jobValue.value.split(/\s+/);
         var maxWords = 2; 
         var numWords = words.length;
         if(numWords &gt; maxWords){
          jobValue.preventDefault(); 
          }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input type="text" id="wordIntent" onkeydown="wordLimit()" &gt; </code></pre>
  </div>
  </div>
  </p>