How to validate a form field for a barcode format like ABCD0312

This guide shows how to create a validation rule that ensures: The first 4 characters are uppercase letters (A–Z) and the last 4 characters are digits (0–9)

Scenario

You have a field called "barcode" in your form, and you want to match it against this structure:

AAAA0000
↑   ↑
|   └── Four digits
└────── Four capital letters

For example, the following inputs should be considered valid:
Input Valid?
ABCD0312 ✅ Yes
abcD0312 ❌ No
ABCD123 ❌ No
A1C20312 ❌ No
ABCD03123 ❌ No
 
 
 
 
 
 

Rule Configuration

Step 1 - In the barcode field, navigate to the 'Field Validation Rules' tab

Step 2 - "Mark form as Valid without message, when"

data["Barcode"] =~ "^[A-Z]{4}[0-9]{4}$"

This regex means:

  • ^[A-Z]{4} → Starts with 4 capital letters

  • [0-9]{4}$ → Ends with 4 digits

  • ^...$ → Anchors it to exactly 8 characters, no more, no less


Step 3 -
 Add a new validation rule with the '+' icon

Step 4 - Click the 'valid' button to change to 'Invalid' and select a colour

Step 5 - "Otherwise, mark form as Invalid without message, when"1

1==1

This always evaluates as true, meaning any unmatched input is invalid by default.