Restricting text response with exactly 8 to 10 words while collecting data

Hi everyone, contrarily to many posts that I’ve seen in the forum, I would like to add/reduce character limit to a TEXT question. Does anyone know if it is possible to do that and how?
My interest is to have an answer in the text question that is limited to maximum 8-10 words (max 70 characters with spaces, or 67 without spaces).

Thanks a lot for your support and for sharing experiences with a fairly new user!

Best
Gabriele

Hello,
You probably can do this with a combination of regex and string-length.
I am afraid there n=is no simple possibility to count “words”.
For better support, it would be good if you can specify more in detail what exactly you will allow also. For example: hi? hi hi hi? #hi? … hi hi? hi?
Can you also tell us which KoBo tool (KoBoCollect or Enketo) and server you use.:

To give you an idea, a combined constraint:
string-length(normalize-space(.)) <= 67 or regex( ., ‘^.[a-zA-Z]{3,}.$’)
would restrict to
Input of maximal 67 length, after leading, trailing and double blanks removed, and at least one 3 letter word (anywhere).

1 Like

Hi @GVitale,

Adding to what @wroos has advised, you could also do it by slightly editing the code that has been outlined in the support article Restricting text responses with regular expressions.

image

To restrict the words to exactly 8 words:

regex(., '^\W*(\w+\b\W*){8}$')

To restrict the words to exactly 10 words:

regex(., '^\W*(\w+\b\W*){10}$')

Have a great day!

1 Like