Custom validation to avoid certain word in free text field. | XM Community

Custom validation to avoid certain word in free text field.

  • 27 July 2021
  • 3 replies

Can someone please help.
I have few hundreds of words to be avoided being entered in the free text field while user answering the survey.
Only option I see is to add one condition for each word.
Can someone help with the java script code if its possible.


Best answer by cbhavsar 30 July 2021, 09:06

View original

3 replies

Userlevel 4
Badge +24

Here is the script you are looking for. Try modifying it based on your requirement.
var substrings = ["Monday", "Tuesday", "Wednesday"];
var str;
str = "Hey, today is Monday!";
if (new RegExp(substrings.join("|")).test(str)) {
    console.log("Text have a word from array!");
} else {
    console.log("Text don't have any word from array!");
All the very best for your project!

Thanks cbhavsar .
Do you have any idea how can I use this code in Qualtrics for validation of the entered text?

Userlevel 4
Badge +24

Using Jquery or Javascript you can fetch the text and store it in str variable of my script earlier. I suggest you should execute this script before page unload.
In case you are looking where you can place JS, then click on the question - the last option in the left pane would be Javascript and there you should add script under Qualtrics.SurveyEngine.addOnUnload

Leave a Reply