Have an idea?

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

Constraining the field to only 5 capital letters

Hi,

I have free format question that asks for text input and I want to limit the input to only 5 Capital letters. I found the related script to constrain to letters only but I am not sure how to constrain to the specific number of letters (5)

Regards
asked Jun 7, 2019 by AMYN Bronze (2,980 points)

1 Answer

+1 vote
 
Best answer
This regular expression represents exactly five capital letters:

/^[A-Z]{5}$/
answered Jun 7, 2019 by Zachary Platinum Sawtooth Software, Inc. (205,575 points)
selected Jun 14, 2019 by AMYN
thank you for the code, but I realized that I wanted them to enter between 1 to 4 capital letters. I tried this code but it seems that it is not working or something is missing.
var resp = SSI_GetValue('[% QuestionName() %]');
var regex = /^[A-Z]{1,4}$/;
if (resp && !regex.test(resp)) {
    strErrorMessage = '必须用大字母,不超过4个字'; 
}

the Chinese error message means
(means that you have to use capital letters and 4 at max)
Thanks again for the continuous support
What about that behavior is not right?
I added that code to the advanced > custom javascript verification & adjusted it to be called (after) the system verification.
I tried to enter 5 capital letters & it did not pop any notifications and I moved on and continued the questionnaire normally.
I tried "ABCDE" with your "{1,4}" code and couldn't advance.  If that's not what you're seeing, could you share your .ssi with support@sawtoothsoftware.com so I can take a closer look?
I found the problem, it was in the name of the recalled variable as it has some modification from the question name.
It worked fine now.
Thanks a lot
...