Community Groups are officially here!
We've released Groups, a new feature that enables us to connect community members of similar industries and interests in a shared, private space. You can check out all of the details here, including information about who can join, how to join, and what Groups are currently offered. Please leave your feedback through this Community Groups Feedback Survey.

Custom validation to avoid certain word in free text field.

Subhransu India Qubie ✭
edited August 2 in Custom Code


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 Answers

  • cbhavsar
    cbhavsar Mumbai, India Guru ✭✭
    Accepted Answer


    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!

  • cbhavsar
    cbhavsar Mumbai, India Guru ✭✭
    Accepted Answer

    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


  • Subhransu
    Subhransu India Qubie ✭

    Thanks @cbhavsar .

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