Limit the max characters allowed in comments

Are your readers writing their own version of War and Peace in your comments?

We really hope you aren't getting comments like this...but it's possible

Comments can be useful, but if you're finding that people are sending inappropriately long comments, limiting them to a set number of characters can help encourage them to shorten things up.

We have a script you can adapt to limit the total number of characters for the comments and show commenters how many characters they have remaining.

To add this character limit to your comments:

  1. Go to Settings > Style.
  2. Below the preview pane, click on Custom HTML  and select Article from the dropdown.
  3. Copy the script below and paste it into the bottom of the Custom HTML:
    <script>
      $(function(){
        //Set character limit on comments
        var maxchars = '300'; //Change this number to change the character limit
        $('.hg-comment-post textarea').before('<div class="text-right"><span id="remain">'+maxchars+'</span> characters remaining</div>');
        $('.hg-comment-post textarea').keyup(function () {
             var tlength = $(this).val().length;
             $(this).val($(this).val().substring(0, maxchars));
             var tlength = $(this).val().length;
             remain = maxchars - parseInt(tlength);
             $('#remain').text(remain);
        });
      });
    </script>
  4. In row 4, change the number set for var maxchars to the number of characters you want to use. Be sure it stays in 'single quotes'.
  5. Save.

Readers will be shown the maximum character count and it will count down as they type. They will not be able to type more than the allowed characters. It even works with copy and paste.

We've added the code to this page so you can see it in action. We set a limit of 140 characters so if you can't tweet it, it won't fit in a comment!