Limit characters words in multiple choice text entry | XM Community
Skip to main content

I am trying to limit the number of characters (2,500) or words (350) in a multiple choice question that allows text entry (e.g., other please specify response).

I know I have 2 options: a) custom validation using regex or b) javascript. I tried the following regex but it did not work.
^(?:\\b\\w+\\b*){1,350}$

Anything longer than 1 line in the text box gets flagged. Below you'll see an example I used that should not have been flagged and it was.

Any suggestions?

Screen Shot 2022-02-28 at 3.26.26 PM.pngScreen Shot 2022-02-28 at 3.26.45 PM.png

Hi smgreenPhD Can you try the below JS and let me know if this works out for you?
Qualtrics.SurveyEngine.addOnload(function()
{
jQuery("#"+this.questionId+" .InputText").each(function () { 

 jQuery(this).attr('maxlength','19');

});
});


@Aanurag_QC No, the JS did not work. It allowed me to input 3000 words with no issue.


Hi smgreenPhD Can you please clear the Javascript and paste this again. For me, it works fine.


@Aanurag_QC I edited the question javascript. See pic. Am I putting the Javascript in the right location?
Screen Shot 2022-03-03 at 8.29.08 AM.png
In survey preview I added 1,000 word text and it submit fine without any limitation. It should not do that.


smgreenPhD For me its not allowing more than 19 characters using the same JS:
image.png


I placed it within the question and not in the header of the survey


I was actually able to figure out a regex solution before I saw your latest response.
For regex, I used this:

^\\W*(?:\\w+\\b\\W*){0,350}$


Leave a Reply