Search the knowledge base, browse our resources, and visit our forum for more detailed information
Last updated: 21 Mar 2026
A regular expression, or regex, is a search pattern used to match specific characters or character ranges within text. Regular expressions are commonly used to validate, search, extract, or restrict text input.
In KoboToolbox, regular expressions are typically used to control how users enter data. For example, you can restrict a mobile number to exactly 10 digits, enforce a specific ID format, or limit text to uppercase letters only.
This article provides an overview of common regular expression components and practical examples you can use to validate and restrict text input in your forms.
To learn more about using regular expressions in your forms, see Introduction to form logic in XLSForm and Introduction to form logic in the Formbuilder.
Regular expressions in KoboToolbox are written inside the regex() function. For example, regex(., '^[0-9]{10}$') restricts an input to exactly 10 digits.
The following tables describe commonly used regex elements.
Regex |
Description |
|---|---|
|
Matches the start of a string |
|
Matches the end of a string |
|
Groups characters together |
|
Matches one pattern or another (logical OR) |
Regex |
Description |
|---|---|
|
Matches a, b, or c |
|
Matches any lowercase letter |
|
Matches any uppercase letter |
|
Matches any digit from 0 to 9 |
|
Matches letters or digits |
|
Matches any character except a, b, or c |
|
Matches any character except uppercase letters |
Regex |
Description |
|---|---|
|
Matches any digit (same as [0-9]) |
|
Matches any non-digit |
|
Matches any word character (letters, digits, _) |
|
Matches any non-word character |
|
Matches a space or tab |
|
Matches a word boundary |
|
Matches a literal dot ( |
|
Matches a literal |
|
Matches a literal |
|
Matches a literal backslash ( |
|
Refers to a previously matched group |
Regex |
Description |
|---|---|
|
Matches zero or one occurrence |
|
Matches zero or more occurrences |
|
Matches one or more occurrences |
|
Matches exactly x occurrences |
|
Matches at least x occurrences |
|
Matches between x and y occurrences |
The following examples can be used as constraints or validation criteria in your forms.
Regex |
Description |
|---|---|
|
Limit input to numbers |
|
Limit input to 2 digits |
|
Limit input to 2-4 digits |
|
Limit input to 10 digits |
|
Limit input to a number between 1 and 100 (e.g., for a percentage) |
|
Limit input to 9 digits, first digit cannot be 0 |
|
Limit input to number formatted as 12.345 |
|
Limit input to 10, 13, or 17 digits |
|
Input must be 12 or 345 |
Regex |
Description |
|---|---|
|
Limit input to letters, spaces, and symbols (no numbers) |
|
Limit input to letters |
|
Limit input to letters and spaces |
|
Limit input to 1–6 lowercase letters |
|
Limit input to 1–10 uppercase letters |
|
Input must match one word from the list |
|
Allows color or colour |
|
Limit input to uppercase letters and spaces only |
|
Limit input to lowercase letters and underscores ( |
Regex |
Description |
|---|---|
|
Limit input to exactly 3 letters, digits, or underscores ( |
|
Limit input to one letter and eight numbers |
|
Limit input to a specific ID format |
|
Limit input to exactly 3 words |
|
Limit input to common email format |
For additional help building and testing patterns, visit: http://www.regexr.com/
Did you find what you were looking for? Was the information clear? Was anything missing?
Share your feedback to help us improve this article!
KoboToolbox is maintained by Kobo Inc.