Using RegEx in Question Validation

Written By Jessica Moore (Super Administrator)

Updated at August 19th, 2026

In short  A regular expression, or RegEx, is a pattern used to check text. For example, ^[a-zA-Z]+$ accepts one or more letters and rejects numbers, spaces, and punctuation.

How RegEx works

A pattern describes what is allowed between the beginning and end of an answer. RegEx is especially useful when a field must follow a predictable structure, such as a reference number or postcode.

Element Example Meaning
Anchors ^  and  $ Start and end of the answer.
Groups [a-zA-Z] Any one character from the group.
Quantifiers *  +  {1}  {1,10} How many times the preceding item may occur.
Tokens \s  \w  \d Whitespace, a word character, or a digit.
Alternation A|B Either the expression on the left or the right.

 

Add a RegEx validation

  1. Open the scheme in the Question Set Editor and edit the question you want to check.
  2. Open the Validation area and add or edit the relevant condition.
  3. Select the answer or field that the condition should evaluate.
  4. Choose Matches RegEx or Does not match RegEx from the comparison list.
  5. Enter the pattern in the value field, then configure the warning text shown to the user.
  6. Save the question and test valid, invalid, and empty answers in the quote journey.

 

 

The condition list includes both matching and non-matching RegEx comparisons.

Choose the right comparison

The comparison becomes true in different circumstances:

  • Matches RegEx: true when the answer fits the pattern.
  • Does not match RegEx: true when the answer fails the pattern.

Recommended validation logic  If the warning is displayed when the condition is true, use Does not match RegEx so the warning appears for an invalid answer.


 

Ready-to-use patterns

These examples use ^ and $ so the whole answer must match, rather than only a portion of it.

Use Example answer Pattern
Letters only Alice ^[a-zA-Z]+$
Letters and spaces Alice Moore ^[a-zA-Z ]+$
Person name Anne-Marie O'Neil ^[A-Za-z][A-Za-z '\-]*$
Digits only 123456 ^[0-9]+$
Exactly six digits 123456 ^[0-9]{6}$
Reference: AA-123456 AB-004275 ^[A-Z]{2}-[0-9]{6}$
Practical email shape name@example.com ^[^\s@]+@[^\s@]+\.[^\s@]+$

 

UK postcode example

A postcode pattern can become long because it must allow several valid outward-code structures. The following is based on the supplied SchemeServe example and allows an optional space before the final three characters:

^(?:[Gg][Ii][Rr] 0[Aa]{2}|(?:[A-Za-z][0-9]{1,2}|[A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2}|[A-Za-z][0-9][A-Za-z]|[A-Za-z][A-Ha-hJ-Yj-y][0-9][A-Za-z]?)\s?[0-9][A-Za-z]{2})$

Test a broad set of real valid and invalid postcodes before using a complex pattern in production. Where available, SchemeServe's dedicated address or postcode question types may be easier to maintain.


 

Important pattern behaviours

  • Use anchors for whole-answer checks. Without ^ and $, a matching fragment may be enough for the condition to succeed.
  • Choose + or * deliberately. + requires at least one character; * also accepts an empty answer.
  • Treat mandatory input separately. A format pattern and a required-field rule answer different questions.
  • Be explicit about letter case. Use [a-zA-Z] when both cases should be accepted unless you have confirmed case-insensitive behaviour.
  • Avoid unnecessary complexity. A shorter, understandable pattern is easier to support than a theoretically exhaustive one.
  • Do not add / delimiters. Enter the pattern itself, such as ^[0-9]+$, unless your SchemeServe configuration specifically instructs otherwise.
  • Test before publishing
  • Use regex101 to build and explain a pattern, then test it inside SchemeServe. External testers support several RegEx flavours, while the supplied SchemeServe material does not identify the exact engine or flavour used by Question Set Editor.

 

Pattern tester: regex101: build, test, and debug regex

For each pattern, test at least:

  • A normal valid answer.
  • Valid minimum and maximum lengths, plus an empty answer.
  • Leading or trailing spaces and lowercase or uppercase variants.
  • Punctuation, accented characters, or symbols users may reasonably enter.
  • A clearly invalid answer that must display the warning.

 

Troubleshooting

  • The warning appears for valid input: The comparison may be reversed. Check whether the validator should use Matches RegEx or Does not match RegEx.
  • Part of an invalid answer is accepted: Add ^ at the start and $ at the end so the entire answer must match.
  • Blank answers are accepted: Replace * with + where at least one character is required, and check the question's mandatory setting.
  • Spaces cause a failure: Allow a literal space or use \s only where whitespace is genuinely permitted.
  • The tester works but SchemeServe does not: Confirm the selected RegEx flavour and simplify unsupported constructs. The final behaviour must be verified in SchemeServe.