title: How to detect line breaks in a text area input?
body: <p><strong>What is the best way to check the text area value for line breaks and then calculate the number of occurrences, if any?</strong></p>
  <p>I have a text area on a form on my webpage. I am using JavaScript to grab the value of the text area and then checking its length.</p>
  <h3>Example</h3>
  <pre><code>enteredText = textareaVariableName.val();
  characterCount = enteredText.length; // One line break entered returns 1
  </code></pre>
  <p>If a user enters a line break in the text area my calculation above gives the line break a length of 1. However I need to give line breaks a length of 2. Therefore I need to check for line breaks and the number of occurrences and then add this onto the total length.</p>
  <h3>Example of what I want to achieve</h3>
  <pre><code>enteredText = textareaVariableName.val();
  characterCount = enteredText.length + numberOfLineBreaks;
  </code></pre>
  <hr />
  <p>My solution before asking this question was the following:</p>
  <pre><code>enteredText = textareaVariableName.val();
  enteredTextEncoded = escape(enteredText);
  linebreaks = enteredTextEncoded.match(/%0A/g);
  (linebreaks != null) ? numberOfLineBreaks = linebreaks.length : numberOfLineBreaks = 0;
  </code></pre>
  <p>I could see that encoding the text and checking for <code>%0A</code> was a bit long-winded, so I was after some better solutions. Thank you for all the suggestions.</p>