Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Can I limit the number of words in a text box?

asked Oct 28, 2015 by anonymous
Under the settings tab of an open-ended question, you can limit the number of characters (see Maximum Number of Characters field).

To limit the number of words, you will have to apply some JavaScript.

1 Answer

+2 votes
Sawtooth can support for character restriction only , if you need number restriction you can try below code :

var sp=/\s+/;
var b=$("#[% QuestionName() %]").val();
//var spclchar=/^^[.`,*:;"'~!@#$%\[\]|^&*()_+\-=\/?>{}<]+[.`,*:;"'~!@#$%\[\]\s|^&*()_+\-=\/?>{}<]*$/;
var spclchar=/^^[\\.`,*:;"'~!@#$%{}\[\]|^&*()_+\-=\/?><]+[.`,*:;"'~!@#$%{}\[\]\s|^&*()_+\-=\/?><]*$/;
var flow=true,flow1=false,flow2=false;
var character =""+SSI_GetValue("[% QuestionName() %]");
var n=5;                                            //n - minimum no .of words required
var chararray=character.split(sp);
var length=chararray.length;
for(var i=0;i<=length;i++)
    if(i<n && spclchar.test(chararray[i]))
    strErrorMessage="You forgot to answer this question.";
if((($.trim(b)!="" && spclchar.test($.trim(b))) || flow1) && flow)
    strErrorMessage="Please provide a valid response.";
if(length<n && flow)
strErrorMessage="Your response must contain at least 5 words.";
$("#[% QuestionName() %]").addClass("error_highlight");
answered Feb 2, 2016 by sandeepkapalawai Bronze (1,455 points)