When adding free text or single string fields into your forms, you can add Regular Expressions to the fields to help ensure that the data you are collecting is in the right format. This can be incredibly useful if you need to export data in a certain format at the end of your process, as it will allow you to ensure that it is being input correctly in the first instance.
Common examples of this include ensuring that bank account details are the correct number of digits, or post codes being in full capitals etc, whilst you may also require candidates to enter their names with a capital letter first - all of this is possible with Regular Expressions.
Important - As writing Regular Expressions can be fairly complicated & a skill in itself, this is not something that our Success team can support with or provide advice on. However, this FAQ details some of the more common examples that you are likely to need, whilst other resources are available online if you are keen to learn how to come up with your own regular expressions!
Adding Regular Expressions
To add regular expressions to the field, navigate into the form and click into the Questions tab. From here, you can either add the field to the form or if it has already been added, click into the field. If regular expressions are available on this particular field, you will see the option as part of the field settings.
Once ticked, you can enter the Regular Expression itself, as well as determine the appropriate error message if the expression is not met. For example, if you require 8 digits in a specific format, you can use the error message to highlight to the candidate what they need to enter.
Hints and Tips
Before you get started in adding regular expressions into your system, there are a couple of things to keep in mind to ensure that they are configured correctly:
- You always need to define the length within the regular expression, regardless of using any additional min / max length fields associated with the question.
- You can add a length range using {X,Y}, replacing X with the minimum in the range and Y with the max.
- For a specific character length, remove Y from the above and replace X with the required number of characters. i.e {9}.
- For unlimited characters, use * before $ (which indicates the end of the line).
Restrict to X number of numeric digits: | ^[0-9]{X}$ |
This is great for fields like Account Number or Sort Codes, where you can replace X with either 8 or 6. ^[0-9]{8}$ |
Restrict to a range of numeric digits: | ^[0-9]{X,Y}$ |
This can be useful if you have ID numbers, which could range from 7 to 9 digits: ^[0-9]{7,9}$ |
Restrict to allow for an unlimited number of uppercase or numeric digits: | ^[A-Z0-9]*$ | This is effective for post codes, where it can be a combination of uppercase or numeric digits, but can also vary in length. |
Unlimited Upper or Lowercase digits (no numbers): |
^[A-Za-z]*$ |
Can be effective for names of people or towns. |
Unlimited Upper or Lowercase, as well as numbers: | ^[A-Za-z0-9]*$ | This is used when you need to avoid special characters, such as ', -, or &. |
NI Number Standard UK format: | ^([A-Z]){2}?([0-9]){2}?([0-9]){2}?([0-9]){2}?([A-Z]){1}?$ | This allows for two uppercase character, followed by numbers, finishing with one uppercase character. |