WordPress.org

Ready to get started?Download WordPress

Forums

Limiting Comments (5 posts)

  1. 5115
    Member
    Posted 6 years ago #

    Is there a way to limit the amount of words or letters in the text area within the comments section so users don't post such long comments?

  2. 5115
    Member
    Posted 6 years ago #

    Alright, I found this code:

    <script type="text/javascript"><!--
    var wordLen = 255; // Maximum word length
    function checkWordLen(obj){
    var len = obj.value.split(/[\s]+/);
    if(len.length > wordLen){
    alert("You cannot put more than "+wordLen+" words in this text area.");
    obj.oldValue = obj.value!=obj.oldValue?obj.value:obj.oldValue;
    obj.value = obj.oldValue?obj.oldValue:"";
    return false;
    }
    return true;
    }
    //--></script>

    and for the textarea:
    <textarea rows="15" cols="30" name="t1" onchange="checkWordLen(this);"></textarea>

    (I know the pop-up would be annoying but, it would prevent readers posting mile long comments.)

    The above code almost works. But, after you hit the submit button WordPress still accepts the comment after getting the notice that you have entered too many words. Could anyone help me implement this code so it is functional with WordPress? Or is there an alternative script I can use?

    Thanks in advanced.

  3. IainPurdie
    Member
    Posted 6 years ago #

    Check out http://wordpress.org/support/topic/66084?replies=2. Might be what you're looking for.

  4. 5115
    Member
    Posted 6 years ago #

    @IainPurdie: Thanks for posting that link! Perfect solution.

  5. GregMulhauser
    Member
    Posted 5 years ago #

    There's also a new plugin that will do the trick for you:

    Greg's Comment Length Limiter

    All the best,
    Greg

Topic Closed

This topic has been closed to new replies.

About this Topic