Regex patterns for input validation
Regex syntax and ready-to-use patterns for guide step input validation.
When a guide step asks someone to type a value, a validator can check what they enter against a regular expression (regex). This helps for fields like email addresses, postal codes, International Bank Account Numbers (IBANs), and time formats, where the expected input follows a known pattern. This article covers the syntax basics and ready-to-use patterns for common cases. For how to set the validation mode, see Creating validators.
Regex syntax primer
A regular expression is a pattern that describes what a valid input looks like. The table below covers the building blocks you need for most input validation rules.
Start anchor
^
Matches the beginning of the input
^Hello matches "Hello world" but not "Say Hello"
End anchor
$
Matches the end of the input
world$ matches "Hello world" but not "world peace"
Digit
\d
Matches any single digit (0 to 9)
\d\d matches "42"
Word character
\w
Matches a letter, digit, or underscore
\w+ matches "hello_123"
Any character
.
Matches any single character except a newline
h.t matches "hat", "hit", "h9t"
Character set
[abc]
Matches any one of the listed characters
[aeiou] matches any vowel
Zero or more
*
Repeats the previous element zero or more times
ab*c matches "ac", "abc", "abbc"
One or more
+
Repeats the previous element one or more times
ab+c matches "abc", "abbc", but not "ac"
Optional
?
Makes the previous element optional (zero or one)
colou?r matches "color" and "colour"
Exact count
{n}
Repeats the previous element exactly n times
\d{5} matches "80331"
Range
{n,m}
Repeats the previous element between n and m times
\d{3,5} matches "123", "1234", "12345"
Alternation
|
Matches the expression on either side
cat|dog matches "cat" or "dog"
Group
()
Groups elements together, often combined with alternation or quantifiers
(ab)+ matches "ab", "abab"
Escape
\
Treats the next special character as literal
\. matches an actual period
Put ^ at the start and $ at the end of every pattern. Without them, the regex matches any input that contains the pattern anywhere, rather than requiring the entire input to match.
Common patterns
Each pattern below is ready to paste into the regex field in the Editor. The Passes and Fails columns show what to expect when you test.
24-hour time (HH:MM)
^([01]\d|2[0-3]):[0-5]\d$
Hours 00 to 23, colon, minutes 00 to 59
14:30, 08:00
25:00, 8:00 AM
12-hour time (H:MM AM/PM)
^(0?[1-9]|1[0-2]):[0-5]\d\s?(AM|PM)$
Hours 1 to 12, colon, minutes, optional space, AM or PM
2:30 PM, 12:00 AM
13:00 PM, 0:30 AM
Email address (basic)
^[^@\s]+@[^@\s]+\.[^@\s]+$
Something before @, something after, a dot, and a domain
user@example.com
user@, @example.com
German postal code
^\d{5}$
Exactly five digits
80331, 10115
8033, 103115
US ZIP code (with optional +4)
^\d{5}(-\d{4})?$
Five digits, optionally followed by a hyphen and four more
90210, 90210-1234
90210-12, 9021
German IBAN
^DE\d{20}$
Country code DE followed by exactly 20 digits
DE89370400440532013000
DE8937, de89370400440532013000
1 to 5 words
^(\S+\s+){0,4}\S+$
One to five groups of non-whitespace separated by spaces
"hello world", "one"
"this has six words in it"
These patterns are strict by design, which is usually what you want for form validation. If a pattern is too restrictive for a specific use case, loosen it by adjusting the character classes or quantifiers.
Tips
Test every pattern before publishing. A wrong regex either blocks users from submitting valid input or silently accepts values that should fail. Use the test field in the Editor to try a few passing and failing inputs before saving.
If the expected input may contain special regex characters (periods, parentheses, plus signs), escape them with a backslash in the pattern. For example, match a literal period with \. rather than ., which matches any character.
The Editor can also draft a starting pattern from a plain-language description with AI. This uses the same AI service as the AI Assistant and saves time on unfamiliar formats. Always review and test the result before publishing.
Relevant articles
Creating validatorsCreating guidesAI features: what data is processed and whereFAQ
Last updated
Was this helpful?

