Limiting number of words in a response

Lovescuba56 Orlando, FL Community Member Qubie ✭
edited July 28 in Custom Code

I need to limit response to a maximum of 500 words. I have no idea what steps to take to do it. I have tried finding the answer in the community. Found one that said to use ^\s(\S+\s+){0,249}\S$ (which I changed the number to 500), and used the script provided:

    var display = $('wordCountDisplay');
    var questionID = this.questionId;
    var textbox =$('QR~' + questionID);
    var that = this;
    function countWords(s){
        s = s.replace(/\n/g,' '); // newlines to space
        s = s.replace(/(^\s*)|(\s*$)/gi,''); // remove spaces from start + end
        s = s.replace(/[ ]{2,}/gi,' '); // 2 or more spaces to 1
            if(s == ''){
                return 0; 
                return s.split(' ').length; 

    textbox.onkeyup = function(e){


I must be missing a step? Can someone please help me?


Sign In to Comment

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!