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}\$/`).

## 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.

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: Generate regular expressions

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