title: TINYMCE Length : asp.net mvc
body: <p>this is my code to check the length of tinymce contant </p>
  
  <pre><code>&lt;script type="text/javascript" src="//tinymce.cachefly.net/4.0/tinymce.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          window.onload = function () {
              tinymce.init({
                  selector: 'textarea',
  
                  setup: function (ed) {
                      ed.on('keyup', function (e) {
                          var count = CountCharacters();
                          document.getElementById("character_count").innerHTML = "Characters: " + count;
                      });
                  }
              });
          }
          function CountCharacters() {
              var body = tinymce.get("Body").getBody();
              var content = tinymce.trim(body.innerText || body.textContent);
              return content.length;
          };
          function ValidateCharacterLength() {
              var max = 4000;
              var count = CountCharacters();
              if (count &gt; max) {
                  alert("Maximum " + max + " characters allowed.")
                  return false;
              }
              return;
          }
      &lt;/script&gt;
  </code></pre>
  
  <p>it return the length without  (html tags) so the max size is 4000 but if i make it bold , Chang color 
  it be more than 4000 so can't store it in SQL
  how i can determine the length with HTML tags ?</p>
  
  <p>e.g : this is the length with bold <a href="https://i.stack.imgur.com/RbFai.png" rel="nofollow noreferrer">enter image description here</a> </p>
  
  <p>but in SQL it the lenght :33</p>
  
  <p>i change code to as bellow </p>
  
  <pre><code>@model TinyEditorWithMVCApp.Models.Post
  
  
  @{
      ViewBag.Title = "AddPost";
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  &lt;h2&gt;Add new Post&lt;/h2&gt;
  
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta name="viewport" content="width=device-width" /&gt;
      &lt;title&gt;TintMCE App&lt;/title&gt;
      &lt;script type="text/javascript" src="//tinymce.cachefly.net/4.0/tinymce.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          window.onload = function () {
              tinymce.init({
                  selector: 'textarea',
  
                  setup: function (ed) {
                      ed.on('keyup', function (e) {
                          var count = CountCharacters();
                          document.getElementById("character_count").innerHTML = "Characters: " + count;
                      });
                  }
              });
          }
          function CountCharacters() {
      var content = tinymce.activeEditor.getContent({format: 'raw'});
       return content.length;
  };
          function ValidateCharacterLength() {
              var max = 4000;
              var count = CountCharacters();
              if (count &gt; max) {
                  alert("Maximum " + max + " characters allowed.")
                  return false;
              }
              return;
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div&gt;
          @using (Html.BeginForm("AddPost", "Home", FormMethod.Post))
          {
              &lt;div&gt;
                  @Html.TextBoxFor(model =&gt; model.AuthorName)
              &lt;/div&gt;
  
              &lt;div&gt;
                  @Html.TextAreaFor(model =&gt; model.Body)
              &lt;/div&gt;
  
              &lt;div id="character_count"&gt;
              &lt;/div&gt;
              &lt;div&gt;
                  &lt;input type="submit" value="Save Post" onclick="return ValidateCharacterLength();" /&gt;
  
  
              &lt;/div&gt;
  
          }
      &lt;/div&gt;
      &lt;div id="character_count"&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>i guess that get incorrect result </p>
  
  <p>it give me that the character 8 even it's (test) must be 4 and i don't add any HTML tags <a href="https://i.stack.imgur.com/eecRU.png" rel="nofollow noreferrer">enter image description here</a></p>