How can I validate a zip code?

Here are two ways to check if an entered zip code (or postal code) is valid:

  • Check the zip code and display an error if the entered zip code is not in the approved or valid list:

    1. Add an internal Textbox field to your form labelled ‘Valid Zip Codes’. Set the default value to a comma-separated list of all the valid zip codes, ex: 10451,10452,10453,10454,10455,10456,10457,10458
    2. Add an Address field with the Zip Code option included. In the field settings, select Custom Error > When and use an expression to compare the entered zip code with the list of valid zip codes:
      =(!ValidZipCodes.Contains(Address.PostalCode))
    3. Make sure to include a custom error message (ex: “Your zip code is not supported.”), and save your changes.
      How to validate a zip code.
  • Display a specific value based on the entered zip code in another field:

    1. Add an Address field to your form with the Zip Code option included.
    2. Add three Calculation fields to your form:
      • Name the first Calculation field “Index” and set the type to Number. Use the following calculation: =Mapping.IndexOf(Address.PostalCode) + Address.PostalCode.Length + 3
      • Name the second Calculation field "Zone Calculation and set the type to Text. Use the following calculation: =Mapping.Substring(Int32(Index), Mapping.IndexOf("""",Int32(Index)) - Int32(Index))
      • Name the third Calculation field “Mapping” and set the type to Text. Here, you will insert your list of zip codes and associated values, ex: "12345" "Zone A";29063" "Zone D";"11111" "Zone B"
        How to check if a post code is valid.

In the example above, we took the Zone Calculation field value and set it as the default value for the “Zones” Choice field with associated prices.

Learn more about advanced validation.