title: jQuery function to limit text entry based on word-count not working while pasting text
body: <p>this is the jquery code</p>
  
  <pre><code>var max_count = 200;
  $(document).ready(function () {
  var wordCounts = {};
  $("#word_count").keyup(function () {
      var matches = this.value.match(/\b/g);
      wordCounts[this.id] = matches ? matches.length / 2 : 0;
      var finalCount = 0;
      $.each(wordCounts, function (k, v) {
          finalCount += v;
      });
      var vl = this.value;
      if (finalCount &gt; max_count) {
          vl = vl.substring(0, vl.length - 1);
          this.value = vl;
      }
      var countleft = parseInt(max_count - finalCount);
  
      $('#display_count').html(finalCount);
      $('#count_left').html(countleft);
      am_cal(finalCount);
  }).keyup();
  });
  </code></pre>
  
  <p>The work of this code is to count the number of words and limit them going up 200. </p>
  
  <p>When we type in the textarea it works fine, and it counts and when it reaches 200 it does not allow to write more, but when i copy paste the code, it keeps going above 200, how can i correct this?</p>
  
  <p>here is the fiddle</p>
  
  <p><a href="http://jsfiddle.net/aVd4H/" rel="nofollow">http://jsfiddle.net/aVd4H/</a></p>
  
  <p>Thanks in advance</p>