Difficulty using Matching Regex | XM Community
Skip to main content

In my survey, only respondents that reside within certain CA zip codes will be able to qualify to participate. I was informed that I can use Matching Regex for this purpose in the the Survey Flow. I was informed that I needed to include zip codes that would exclude participants. When I was testing the survey, I was not disqualified, though I entered a zip that should disqualify me. I am not sure what the issue is and any help is appreciated. Below is a screen shot of some of the survey flow with the Regex.
image.pngimage.png

Since you have a list of codes, I would recommend using either contains or JS for this. Regex is for matching patterns.
So, suppose you want to select only zip codes that start with 900, then the regex will be ^90{1,2}[1-9]\\d+$, where the symbols mean the following:

  • ^ start of the line

  • 9 matched literally.

  • 0{1,2}: Match either 1 or 2 zeros

  • [1-9]: Match 1 character between 1 and 9

  • \\d+: Match continuous characters between 0-9 (as many)

  • $: End of line

This sequence will match 90111, 90011, but not 90001 or 91000. For details look here.
Unless you have well defined or extremely complicated patterns, I wouldn't recommend regex.
If you would like to use JS, add this code to the question where you are asking for the pincode:
Qualtrics.SurveyEngine.addOnPageSubmit(function () {
    good_pins = ("${e://Field/good_pins}").split(",").map(Number);
    pin = Number(document.querySelector("#QR\\\\~" + this.questionId).value);

    good_pins.forEach((num) => {
        if (num == pin) {
            Qualtrics.SurveyEngine.setEmbeddedData("exit", 0);
        }
    });
});
You'll need to store the all the pins in an embedded data called
good_pins 
separated by a comma and then branch them out if
exit 
is not equal to zero


Leave a Reply