Validation
- Updated
Sometimes in surveys, you may want to prevent a participant from proceeding based on their response to a survey question. This can be accomplished by configuring survey validation logic.
There are two types of validation within MyDataHelps Designer - rules and patterns. Validation rules are set via the Validation tab and apply to an entire survey step, whereas validation patterns are set within the Properties tab of a survey step and are specific to single questions within the step.
Table of Contents
Validation Rules
Validation rules can be particularly useful in the context of eligibility screening or consent surveys, in which you might not want a participant to proceed unless they satisfy various eligibility criteria.
Adding Validation Rules
To set up validation for a step in the survey editor, go to the validation tab for the step you would like add validation for. Note that you cannot add validation rules to the last step of your survey.
Validation rules are set up similarly to navigation rules and use the same conditional editor.
When you have selected the validation tab for a particular step, click the “Add Validation Rule” button to start adding a validation rule.
You can then set up a condition. For instance, if the step “IS_OVER_18
” has the answer “NO,” you can then enter a message to be displayed if the condition evaluates to true—for example, “You must be over 18 to participate in this study.”
You can set up as many validation rules as you want on a single step. When a participant completes this step, the validation rules will be evaluated in order until one evaluates to true, in which case the message for that rule will be displayed. If none of the validation rules evaluate to true, the participant will be allowed to continue to the next step.
Compound Conditions
You are not restricted to a single conditional when editing a validation rule. By clicking the “AND”, “OR,” and “NOT” buttons you can combine or negate the various conditions.
Validation Patterns
Validation patterns allow study teams to prevent participants from entering faulty data into text answer format questions, thereby reducing the amount of data cleaning required prior to analysis. Common examples include not allowing numbers in a response (e.g., names and cities) or requiring a certain answer format (e.g. phone number with dashes).
[note]Populating certain demographic fields such as Email or Mobile Phone will enforce a specific validation pattern to ensure they are stored in a usable format.[/note]
To use validation patterns, go to the survey page and click into the survey where you would like to add a validation pattern. Go to the Properties tab.
Scroll down and add one the following strings to the "Validation Pattern" field. Next, add text in the "Invalid Pattern Message" field - the text you add here will be shown to participants if they enter invalid data.
Validation patterns only work when the text answer format and require that you specify an "Invalid Pattern Message."
Rule | String | Example |
---|---|---|
No Numbers |
^[^0-9]*$ |
A study team wants to restrict answers to letters and characters only to prevent faulty data. This string allows for special characters (e.g. O'Connor or Martha's Vineyard), but no numbers. |
Phone Format |
\(?[\d]{3}\)*-[\d]{3}-[\d]{4} |
Data managers want participants to enter phone numbers in the same format to make data analysis easier (e.g., `555-888-7777`).
Note: The MobilePhone demographic field has a validation requiring digits only (e.g., `5558887777`). However, you can use the Phone Number answer format to have it display at `(555) 888-7777` during input. |
Email Format |
.+@.+\.[a-z]{3} |
Study coordinators want to ensure participants are entering valid email addresses. |
Optional Items |
^$| Note: Add this string before any other validation pattern for optional items. For example, optional phone number: |
As a PI, I want to leave contact informational optional, but if a participant decides to add their phone number make sure it is entered in a valid format. |
For a tutorial on developing and using validation patterns, visit RegexOne.
Was this article helpful?