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

Limit characters words in multiple choice text entry

  • February 28, 2022
  • 7 replies
  • 442 views

Forum|alt.badge.img

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

Best answer by smgreenPhD

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}$

View original

7 replies

Aanurag_QC
QPN Level 5 ●●●●●
Forum|alt.badge.img+31

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');

});
});


Forum|alt.badge.img
  • Author
  • 3 replies
  • March 2, 2022

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


Aanurag_QC
QPN Level 5 ●●●●●
Forum|alt.badge.img+31

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


Forum|alt.badge.img
  • Author
  • 3 replies
  • March 3, 2022

@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.


Aanurag_QC
QPN Level 5 ●●●●●
Forum|alt.badge.img+31

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


Aanurag_QC
QPN Level 5 ●●●●●
Forum|alt.badge.img+31

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


Forum|alt.badge.img
  • Author
  • 3 replies
  • Answer
  • March 4, 2022

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