Validating specific included/excluded zip codes using JS | XM Community
Skip to main content
Hi, I have a list of zip codes that are included and excluded in a local delivery service. I would like respondents to enter their zip codes and receive a message (or skip logic) that they are eligible or ineligible based on the zip code look up. How could this be done with JavaScript and custom validation or display logic? The list of zip codes is probably between 100-200 entries.
hello @nkumich ,



Step 1: Put all the 100-200 zip code in the js array.



Step 2: Pipe the text entry of the zip code question in js as

var z=" ${q://QID13/ChoiceTextEntryValue}"; //replace qid with your own



Step 3: Use include function of js to check the matching of zip code. Eg:

[1, 2, 3].includes(2); // true

[1, 2, 3].includes(4); // false



Like:

var z=" ${q://QID13/ChoiceTextEntryValue}";

var b=[99501,99502,99503,99504].include(z);

if(b){

//eligible

}else{

//not eligible

}







Follow this page for more info
Hey @nkumich ,



You can also use authenticator
Easiest way is to use contact list authenticator.



Add authenticator at start is survey flow, add all your valid zips in contact list and call this contact list in authenticator. You can here give number of trials also to respondent.

Hi Peeyush,

I added the zips to a directory list, added authenticator at the top of survey flow, but can’t figure out what to do next to screen out respondents based on their text response to my “enter your 5-digit zip” question.


Leave a Reply