Video tutorial about branch conditions.
Using logic3 Min.3 Min.

How to verify given answers with regular expressions

Learn how regular expressions help you to check if given answers comply with your data format standards and use them in branch logic.


When to use

A regular expression is a sequence of characters that specifies a certain pattern in text (more information). In Tripetto you can use such regular expressions in branch conditions to verify if an entered value complies with a certain pattern (or not).

Some examples of regular expression conditions:

  • If the respondent enters a value that starts with 'hi' at the text question 'Question 1', then show this branch (regular expression used for this: /^hi/);
  • If the respondent enters a value that's exactly 8 uppercase characters (for example a discount code) at the text question 'Question 2', then show this branch (regular expression used for this: /^[A-Z]{8}$/);
  • If the respondent enters a value that's exactly 16 digits (for example a social security number) at the text question 'Question 3', then show this branch (regular expression used for this: /^[0-9]{16}$/).

More logic possibilities

The logic described in this article is an example of what Tripetto can do to make your forms smart. Discover the power of branches for your logic to see all logic capabilities.


How to use

As a demonstration scenario we want to verify a social security number that has to contain 16 digits. If the respondent did not enter a valid 16 digits social security number, we will show an error message so the respondent can not continue the form without entering a valid social security number.

We already added a number block for the social security number and we now want to validate that input.

Create branch

To do so we create a branch and we add a Regular expression condition. This opens the regular expression screen right away. In there you can now select the question that you want to validate.

Screenshot of the form builder in Tripetto
Add a regular expression condition and select your question.

Now we can enter the regular expression that we want to apply to the entered value. In this case we simply check if there are 16 digits entered, using this regular expression: /^[0-9]{16}$/. And because we actually want to check if the regular expression is not fulfilled (so we can show an error message in that case), we check the Invert regular expression option.

Tip

You can use regex101.com to create and test your regular expressions.

Screenshot of the form builder in Tripetto
Configure the regular expression condition.

Add follow-up

Now we have setup the branch, we can add the desired follow-up of our form that only will be visible for respondents that haven't entered a valid social security number. In this case we add a raise error block to show an error message.

Screenshot of the form builder in Tripetto
The full setup of a regular expression condition and the follow-up.

That's it! The form will now show an error message, preventing the form to continue, whilst the respondent has not entered a valid social security number.

In this article

    Help us improve