How to use Regular Expression
Have you ever needed to validate input from users to ensure it matches a specific pattern or set of rules? That's where regular expressions, or regex for short, come in handy! A regex is a powerful tool used to match and manipulate text based on specific patterns or rules. Know more!
How do you use regular expressions in BlockSurvey?
If you're using BlockSurvey to create a form, you can easily add regex validation to certain question types, such as email. Here's how:
- Select the question type in the builder.
- Next, navigate to the Validation tab for the email question.
- You can then add your regex pattern along with a custom error message that will be displayed to the user if their input does not match the pattern.
- Once you've published your changes, BlockSurvey will validate user input against your regex pattern and display the error message if necessary.
For example, let's say you want to ensure that a respondent's email address is a Gmail address. You can add the following regex pattern under the Validation tab:
^\w+([.-]?\w+)*@gmail.com$
This pattern will match any input that contains a valid Gmail email address. If a respondent enters an email address that does not match this pattern, they will see the error message you specified under Validation.
Give it a try! Experiment with different patterns and see how regex can improve the quality of your data.