Advanced Webform users may want to consider ways to force certain types of validation that aren't available by default in the feature, but can be accomplished using what are called 'regular expressions' or a 'regex'.
Definition: A regular expression or regex can be described as a special text string for defining a search pattern.
How to use a regex in Webform
Scenario: a user would like to force a guest to only provide an email address with the 'ucdavis.edu' domain. This isn't possible in any of the default options, but can be done using a regex pattern.
- Create your form and add an email element to it.
- In your form's element list page, locate the email element and click its Edit button from under the Operations column.
- Scroll down and locate the Form Validation > Pattern field OR Element Attributes > Element custom attributes (YAML) field. The fields available will depend on the type of element; example, text element will have a pattern field, but an email element will not.
- Enter your pattern. In this case, this pattern will achieve the desired requirement:
- Scroll to the bottom and click Save to finish.
Learn more about regex patterns
Search your preferred tool for 'regex patterns' to find out how to write your own validation patterns.