Validating specific included/excluded zip codes using JS | XM Community
Skip to main content
Solved

Validating specific included/excluded zip codes using JS


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.

Best answer by PeeyushBansal

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.
View original

4 replies

  • 0 replies
  • August 20, 2018
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

  • 0 replies
  • August 20, 2018
Hey @nkumich , You can also use authenticator

PeeyushBansal
Level 6 ●●●●●●
Forum|alt.badge.img+39
  • Level 6 ●●●●●●
  • 1148 replies
  • Answer
  • August 21, 2018
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.

PhilipMoore
Level 2 ●●
Forum|alt.badge.img+11
  • Level 2 ●●
  • 16 replies
  • October 11, 2024

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