If you need a form field to accept exactly four numeric digits, this guide walks you through how to configure that using a regular expression (regex) validation rule in Flow.
🔧 What we're validating
We want to mark a form as valid only if the input is exactly 4 digits
Any other input should be marked as invalid.
✅ Validation Rule Setup
Under the Field Validation Rules tab for your field (e.g., 4Numbers
), use the following logic:
Mark form as Valid without message when:
data["4Numbers"]=~"^[0-9]{4}$"
This regex checks that:
-
^
the input starts... -
[0-9]{4}
...with exactly 4 digits -
$
...and ends there (no extra characters)
❌ Mark form as Invalid
You can add an “Otherwise” condition to catch anything that doesn’t match and mark it as invalid. For example:
1 = 1
This always evaluates as true, meaning any unmatched input is invalid by default.
🧪 Test Examples
Input | Valid? |
---|---|
1234 |
Yes |
12 |
No |
abcd |
No |
12345 |
No |