title: Add line break after n characters, but if it's in the middle of a word cut the whole word and add in next line
body: <p>I am trying to add line break in text area after every 69 characters. I don't want to cut words in middle. if split occurs in middle of the word, take the entire word and put in next line. sample sentence is as follows:</p>
  
  <pre><code>      var sample_txt = "I THOUGHT IT WAS A SIMPLE CONCEPT \nAND DIDN'T FEEL CODE WAS REQUIRED. THE ANSWERS SO FAR SEEM TO HAVE UNDERSTOOD MY EXPLANATION AND SO I AM TRYING THEIR SOLUTIONS NOW. IF I DON'T HAVE ANY JOY I'LL POST SOME CODE. MY IMPLEMENTATION IS ACTUALLY MUCH MORE COMPLEX \nI THOUGHT IT WAS A SIMPLE CONCEPT AND DIDN'T FEEL CODE WAS REQUIRED. THE ANSWERS SO FAR SEEM TO HAVE UNDERSTOOD MY EXPLANATION AND SO I AM TRYING THEIR SOLUTIONS NOW. IF I DON'T HAVE ANY JOY I'LL POST SOME CODE. MY IMPLEMENTATION IS ACTUALLY MUCH MORE COMPLEX";
  
        $(document).on('blur', 'TEXTAREA', function () {
              var arr_lines = sample_txt.split('\n'),
                  char_limit = 69,
                  txt_val = [];
  
              for(var i = 0; i &lt; arr_lines.length; i++){
                  if(arr_lines[i].length &gt; char_limit){
                      var patern = new RegExp('(.{' + (char_limit-1) + '})', 'gi'),
                          arr_txt = arr_lines[i].replace(patern, "$1\n");
                      $.each(arr_txt.split('\n'), function(i,vl){
                          txt_val.push(vl.trim());
                      });
                  }else{
                      txt_val.push(arr_lines[i].trim());
                  }
              }
              this.value = txt_val.join('\n');
          });
  </code></pre>
  
  <p>The string also contains line break entered by the user. I am a spliting them based on '\n' and then count characters and split them again if character exceed limit. the output should be as follows:</p>
  
  <pre><code>I THOUGHT IT WAS A SIMPLE CONCEPT  
  AND DIDN'T FEEL CODE WAS REQUIRED. THE ANSWERS SO FAR SEEM TO HAVE 
  UNDERSTOOD MY EXPLANATION AND SO I AM TRYING THEIR SOLUTIONS NOW. IF
  I DON'T HAVE ANY JOY I'LL POST SOME CODE. MY IMPLEMENTATION IS 
  ACTUALLY MUCH MORE COMPLEX 
  I THOUGHT IT WAS A SIMPLE CONCEPT AND DIDN'T FEEL CODE WAS REQUIRED.
  THE ANSWERS SO FAR SEEM TO HAVE UNDERSTOOD MY EXPLANATION AND SO I 
  AM TRYING THEIR SOLUTIONS NOW. IF I DON'T HAVE ANY JOY I'LL POST 
  SOME CODE. MY IMPLEMENTATION IS ACTUALLY MUCH MORE COMPLEX
  </code></pre>
  
  <p>I looked at some examples at stackoverflow.com but most of the example I found, they just limit the character in one line. They don't put the word in next line.</p>
  
  <p>Please suggest.</p>