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

Validating specific included/excluded zip codes using JS

  • Aug 20, 2018 9:27 PM UTC
  • 4 replies
  • 367 views

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

  • Aug 20, 2018 9:36 PM UTC
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

  • Aug 20, 2018 9:41 PM UTC
Hey @nkumich , You can also use authenticator

PeeyushBansal
Level 7 ●●●●●●●
Forum|alt.badge.img+52
  • Level 7 ●●●●●●●
  • Answer
  • Aug 21, 2018 12:50 AM UTC
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 ●●
  • Oct 11, 2024 9:27 PM UTC

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.