title: Character count for newline in asp.net mvc textarea vs jQuery
body: <p>I'm working on a ASP.NET MVC web application. I have a textarea in the view and it's binded to a model which has maximum length of 1000. </p>
  
  <pre><code>//Html:
  @Html.TextAreaFor(model =&gt; model.Description, 12, 50, new { @class = "form-control", @placeholder = "Mandatory" })
  
  //Model class:
  [Required]
  [DisplayName("Event Description")]
  [MaxLength(1000, ErrorMessage = "Maximum {1} characters.")]
  public string Description { get; set; }
  </code></pre>
  
  <p>I'm also using jQuery to display a message for the user so that they know how many characters are left to enter: </p>
  
  <pre><code>    $('#Description').keyup(function () {
          var maxlen = 1000;
          var count = $(this).val().length;
          var charLeft = maxlen - count;
          var string = charLeft + " chracters left"
          if (count &gt; maxlen) {
              this.value = this.value.substring(0, maxlen);
          }
          else {
              $("#descriptionCharCount").text(string);
          }
      });
  </code></pre>
  
  <p>I found that when there's a new line entered, ASP.NET will insert 2 spaces and therefore increase the character count by 2. But jQuery only increase by 1. This resulting a mismatch. How do I solve this problem?</p>