Do you need a response to be accepted only when it follows a specific format?
For example, your HR team may require an employee ID such as HR-2048, your operations team may use order references beginning with ORD-, or a field may need to accept only a defined set of characters.
In Porsline, you can use Regular Expressions, or Regex, with a Short Text question and Custom Pattern to define the format an answer must follow.
What is Regex?
Regex is a way to define a pattern that describes the format an answer should follow.
Instead of accepting any text a respondent enters, you can define rules that:
- Require an employee ID with a specific structure.
- Require an order reference to begin with a fixed prefix.
- Accept a registration code with a fixed number of digits.
- Prevent whitespace from being entered.
- Allow only selected letters or numbers.
- Require a username or handle to begin with @.
Regex checks whether the format of the response matches the pattern you define. It does not, by itself, verify whether the submitted information exists or is valid in an external system.
When should you use Regex in forms and surveys?
Use Regex when respondents need to enter structured information in a consistent format.
Common use cases include:
- Employee or trainee IDs.
- Order and invoice references.
- Event registration codes.
- Membership numbers.
- Product or branch codes.
- Usernames and handles.
- Verification codes.
- Fields that must not contain whitespace.
- Values that require a fixed number of letters or digits.
For example, if your organisation uses employee IDs such as HR-2048, Regex can prevent respondents from submitting values such as 2048 or hr2048 when they do not match the required format.
Common Regex symbols
You only need a small number of Regex symbols for many common validation patterns.
| Symbol | Meaning | Example |
|---|---|---|
\d | A digit from 0 to 9 | \d{5} means five digits |
\w | A word character | \w+ means one or more word characters |
^ | Start of the answer | ^HR requires the response to start with HR |
$ | End of the answer | \d{4}$ requires the response to end with four digits |
. | Any character except a new line | A.B can match A1B or A-B |
[ ] | One of the characters defined inside the brackets | [A-Z] means an uppercase English letter |
{n} | Repeat the previous element exactly n times | \d{4} means four digits |
{n,m} | Repeat from n to m times | [A-Z]{2,4} means two to four letters |
+ | Repeat one or more times | \d+ means one or more digits |
* | Repeat zero or more times | \d* allows zero or more digits |
\s | A whitespace character | Useful when allowing or preventing whitespace |
Why use ^ and $?
When you want the Regex pattern to apply to the entire response, it will often begin with ^ and end with $.
For example:
^\d{6}$requires the complete response to contain six digits.
By comparison:
\d{6}can match a sequence of six digits within a longer value, depending on how the Regex is evaluated.
For validation rules where the entire submitted value must follow the format, using both anchors helps make the intended pattern explicit.
How to use Regex in Porsline
To create a Custom Pattern:

- Open your survey and go to the Create phase.
- Add a Short Text question.
- Enter the question Label and any instructions respondents need.
- Open the response-pattern settings.
- Review the available predefined patterns.
- If none matches the format you need, select Custom Pattern and enter your Regex.
- Save the question.
- Test both matching and non-matching responses before publishing.

When a response does not match the Custom Pattern, Porsline displays the Validation message so the respondent can correct the answer.
Practical example: Order reference
Suppose an e-commerce operations team uses order references in this format:
ORD-458921The reference begins with ORD- followed by six digits.
Use:
^ORD-\d{6}$Matching responses:
ORD-458921
ORD-120684Non-matching responses:
ord-458921
ORD458921
ORD-4589
458921This pattern requires the exact ORD prefix, the hyphen, and six digits.
If your organization uses another prefix, replace ORD with the code your team uses.
Useful Regex patterns for forms
The following examples use the same core Regex rules and can be adapted to your organization's data format.
1. Employee ID
Employee IDs beginning with HR- followed by four digits:
^HR-\d{4}$Example:
HR-20482. Order reference
^ORD-\d{6}$Example:
ORD-4589213. Event registration code
For codes beginning with EVT-, followed by a four-digit year and another four digits:
^EVT-\d{4}-\d{4}$Example:
EVT-2026-01454. Uppercase alphanumeric code
^[A-Z0-9]{6,12}$This accepts between 6 and 12 uppercase English letters or digits.
Examples:
AB2408
MKT2026
CX4589215. Handle beginning with @
^@[A-Za-z0-9._]+$Examples:
@porsline_en
@customer.cx
@research20266. Prevent whitespace
^[^\s]+$Use this when a code or identifier must be entered without spaces, tabs, or line breaks.
7. Reference divided into four numeric groups
If an internal reference contains four groups of four digits:
^\d{4}-\d{4}-\d{4}-\d{4}$Example:
2026-4582-1048-77218. English letters and numbers only
^[A-Za-z0-9]+$This can be useful for simple internal identifiers that should contain only English letters and digits.
How to test a Regex pattern before publishing
Do not rely only on how the Regex looks. Test the question before sharing your survey.
At minimum, test:
- A response that should be accepted.
- A response that should be rejected.
- Too few or too many characters.
- Uppercase and lowercase letters when case matters.
- Leading or trailing whitespace when relevant.
- A value that looks similar to the correct format but should not match.
For example, if you use:
^HR-\d{4}$test:
HR-2048and then try:
hr-2048
HR2048
HR-248Confirm that the Validation message appears when the response does not match the format you require.
If you're creating a registration workflow, you can also review the Registration Form Template to identify fields where consistent response formats may be useful.
For more information about other question formats, review the Guide to Question Types in Porsline Forms, Surveys, and Quizzes.
You can also explore the Porsline video tutorials for a broader overview of creating surveys and configuring Porsline features.
If you need help setting up a Custom Pattern, contact us at [email protected].