title: javascript textarea character limit per line
body: <p>I have a textarea with limited characters per line. Its function fine.</p>
  
  <pre><code>function limitRow(){
      var count = 1;
      var charsPerLine = row; // 30 characters  
      var maxLines = 20; 
  
      $('.AD_Text_textarea').keydown(function (e) {
          var v = $(this).val(),
          vl = v.replace(/(\r\n|\n|\r)/gm, '').length,
          lineCount = $(this).val().split("\n").length;
  
          if (parseInt(vl / count) &gt;= charsPerLine) {
              if (lineCount &gt;= maxLines) {
                  return false;
              }
              $(this).val(v + "\n");
              count += 1;
          }
      });
  }
  </code></pre>
  
  <p>My question is, if Iam going to line 1, after typing for example 4 rows text and type on for example cursor position 4 some text, then the line counter counts of the beginning and breaks the line after 60 characters and jumps on the end of line 4.<br>
  How can I resolve this problem? 
  I hope, it was clear. (Iam sorry for my english)</p>