Survey constraint

Written by Impact Atlas
Updated 1 year ago

A constraint is a condition that can be applied to a question. Such condition must be satisfied before the value entered into that question is accepted. So if a user’s entry or selection doesn’t meet the constraint, the user will have to correct it before continuing to the next question. This article presents a few examples of how you can use constraints to enhance data quality.

If the user does enter or select a response, they will only be allowed to proceed to the next question when the expression in your constraint column evaluates to true. If the user tries to move forward with a non-blank response but the expression is false, then a generic message "That entry is invalid" will appear. You can also customize your own message that helps the user to understand what value is expected.

In the form builder, you can include a constraint whenever you add or edit a question. There are 2 different types of constraint:

  • Arithmetic

  • Regex

1. Arithmetic

Arithmetic constraints are created by using arithmetic operators between expressions and decision variables. Follow an example below:

1.1. Set ranges of possible responses

The most common way to use a constraint is if you know the range of possible answers for a number field.

This expression requires that the answer be greater than or equal to 0 and less than or equal to 10. If the answer doesn’t meet this constraint, a default message will appear, alerting the user that the response is invalid. You can also create specific messages that provide more information to help the user understand and correct the error.

(x >= 0 && x <=10)

2. Regex

You might want to set constraints on the length, character set allowed and various other fields in the data input by the user. All this can be achieved by using regular expression constraints in your form. Follow some common use cases below:

2.1. Set response lengths

Let’s say that you want to understand how your participants would define the impact of your program in few words. You could use the length constraint to guarantee they will not right a whole paragraphic.

^(?=.{1,20}$).*

This makes it so that the length of the value captured must be between 1-20.

In the form builder you have also have the option to test your regex in the "Test my constraint Regex" field. The button on the right will show "match" or "not match" depending on the answer you enter. So, you can see if your logic is working properly.

Example of answer that matches the constraint of 1-20 characters:

Example of answer that does not match the constraint of 1-20 characters:

2.2. Exactly numbers of characters such as phone number

Another very common use case is to check phone number. One way of doing that is to guarantee only number are entered as well as the number of digits.

^0\d{9}|\d{10}$

2.3. Email checker

To check email address, we usually validate if there are characters prior to the "@", the "@" itself and "." extension after the "@".

^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$

Did this answer your question?