Validation and Error Messages in Surveys

The W2H survey builder allows for the creation of validation criteria for responses to survey questions. This can be as simple as making sure the response to the question “What is your age?” is numeric, or as complex as making sure the response to the question “What is your blood pressure today” meets the formatting criteria for a blood pressure value.

Please note that there may be differences in the validation behavior of web-based survey questions and the validation behavior of SMS Conversation survey questions. Additionally, this page will provide information for validation of Free Text and Text Box question types.

 Instructions

To add a validator to a survey question:

  1. Click the blue “edit” link above the question you wish to validate

  2. Open the gray drop-down panel labeled “Validation”

  3. Click the + symbol to add a new validator, and select the type. The different types of validators and their requirements will be reviewed below

  4. After completing the validator, click “OK”


Types of Validators

A free-text or text-box question can have one of the following validator types:

Numeric

A numeric validator adds the requirement that a free-text response be numeric. It also allows you to set an upper and lower bound on the number that will be accepted as a response. If a participant attempts to enter text, rather than numbers, they will see this error message:

To set upper and lower bounds, enter them into the fields provided. You can also set a custom error message for responses that fall outside the set range:

If a participant tries to enter a response outside of the set range, they will see your custom error message from the “Display” field


Text

A text validator allows you to set an upper and lower bound on the number of characters that will be accepted as a response.

If you wish to add a custom error message, do so in the “Display” field. If nothing is entered into the “Display” field, the automatic error message that appears will read “Please enter at least [minimum] and no more than [maximum] characters.”


Expression

An expression is a piece of logic that dictates the parameters for an acceptable response. An example of an expression might be:

1 {question3} > {question1} AND {question3} < {question2}

Now, let’s unpack what this means. Suppose the questions in this survey are asking about the minimum goal (question1), maximum goal (question2), and an achievable goal (question3) for the number of steps a participant takes in a day. If question 3 is meant to be between the values of questions 1 and 2, we need a way to ensure that participants don’t enter a value less than their minimum or greater than their maximum. We could use a numeric validator…except the the upper and lower bounds will be different for each participant. As such, an expression validator is the way to go.

There are two ways to create an expression validator: with the in-question builder tool, or by manually writing it out. For either way, the first thing you’ll need to do is click on the gray panel that says “Expression is empty”:

We will review how to use the builder first. Select the question you are working on for the first drop-down. Then, select your operator and type in the value. Since we want to use the value of another question’s answer as the lower limit here, put the Question ID of that question in curly brackets (e.g., {question1}:

As you can see, the expression is starting to auto-populate into the gray panel. Next, click the blue “Add condition” button to configure your upper limit:

From here, you can click OK and move on to testing your validator. However, for our purposes, we are going to click the gray “Edit” button to look at the manually-typed expression:

Please note that the single quotes included in the expression above are more important for text answers, but will not interfere with numeric values

The custom error message is perhaps more important for expression validators than any other type. The reason for this is the the default error message looks like this:

While this error message is accurate, it might confuse participants. So make sure to add a custom message in the “Display” field, pictured in the first image of this section.


Regex

Regular Expressions (often shortened to Regex) are slightly more complicated than Expressions. For more information on Regex and how to use them, see https://waytohealth.atlassian.net/wiki/spaces/WTHST/pages/989790225


Email

An email validator is a shortcut around writing an expression to require the elements of an email address be included in the response. The email validator requires that the response be one word (no spaces), and that it contain both an @ symbol and a .com, .net, .edu, etc. It does not, however, validate that the email or domain name is active - for instance, entering fake@12345W2H.org will be accepted.

The only additional field needed for an email validator is the optional custom error message. If nothing is entered, the error message will display as pictured above.