Validate text box entry for zip code

0

I have a survey qualifier question of a text box that asks a user to enter their zip code.  Only zip codes within our metro area are allowed to continue, all others will disqualify.  I have a list of around 330 zip codes to match against.  I know i can set up Skip/Disqualify logic for this, but do not want to have to setup all 330 conditions!

I have been looking for alternatives ways to approach this.  First, is there a non-scripting way to achieve this (match against a list)?  If not, I have been playing with some scripting with no luck (still a rookie in custom scripting).  My first approach has been to have a Hidden Value with the list of zip codes, but that doesn’t seem to work.  The script is below:

%%zip_enter = sgapiGetValue(10); //Zip Code text box
%%zip_list = sgapiGetValue (116); //hidden value holding zip codes

if (%%zip_enter == %%zip_list) {
sgapiJumpToPage(7);
}
if (%%zip_enter !== %%zip_list) {
sgapiJumpToPage(6);
}

My next thought is, is there a way in the script to have the list of zip codes to match?  Not sure how I would approach this.  \

Any help would be greatly appreciated on this!

Ben Grill answered
    0

    I have the same problem but with a much larger postcode list that is in separate blocks i.e. need to exclude anyone that doesn’t live in 2000-2190; 3000-3230; 4000 – 4050; 8000-8115.

    Any other suggestions? Surely someone has come up with a custom script to solve this problem by now as it’s a pretty standard approach in market research.

    Damien answered
      0

      Hi, I created two solutions for this type of problem. The first is a basic check to see if a postcode is valid, the second is more complex and categorises the postcode into a metro or regional area.

      For each of them you’ll have to create a new hidden question in which to store the results and then you can use that hidden question for scripting / routing etc. In the example below a positive match is saved to the hidden question using sgapiSetValue(154,”Yes”)

      VERSION 1

      //Set the postcode question you want to validate
      //Create an array of valid postcodes

      %%needle = sgapiGetValue(7);
      %%haystack = array(“2000″,”2001″,”2002″,”2003″,”2004”);

      //Search the entered postcode against the list of valid postcodes
      //If it matches store Yes value at hidden question
      //If there is no match then store No value at hidden question

      if (sgapiIn_Array(%%needle, %%haystack)){
      sgapiSetValue(154,”Yes”);
      }
      else
      {
      sgapiSetValue(154,”No”);
      }

       

      VERSION 2

      //Set the postcode question you want to validate
      //Create an array of valid metro postcodes
      //Create an array of valid regional postcodes

      %%needle = sgapiGetValue(7);

      %%haystackMetro = array(“2000″,”2006″,”2007″,””6567”);

      %%haystackRegional = array(“800″,”810″,”812″,”820″,”7467″,”7468″,”7469″,”7470”);

      //Search the entered postcode against the list of metro postcodes
      //If it matches store Metro in a hidden question
      //If there is no match then try a new search in the regional postcodes
      //If there is a match then store Regional in a hidden question
      //If there is no match then store None in a hidden question

      if (sgapiIn_Array(%%needle, %%haystackMetro)){
      sgapiSetValue(160,”Metro”);
      }
      else
      {
      if (sgapiIn_Array(%%needle, %%haystackRegional)){
      sgapiSetValue(160,”Regional”);
      }
      else
      {
      sgapiSetValue(160,”None”);
      }
      }

      Ben Grill answered
        0

        I would want to exhaust all possibilities of using the Skip/Disqualify logic before trying custom scripting.  It should not necessary to test against 330  zip codes.  If you are dealing with codes within a specific area, don’t they all fall into a certain range that you can define with Greater Than / Less Than statements?  And you can create multiple Skip/Disqualify conditions to cover all of the exceptions.

         

        Jim W (Moderator) answered
          ×

          Login

          Question stats

          • Active
          • Views3695 times
          • Answers3 answers
          • Followers1 follower