Validations
Validations let you define what makes a field valid or not, and how the user should be informed when it’s not. FormBuilder supports two kinds of validation:
- Simple validation rules as strings, like
requiredoremail - Advanced object-based validations, for custom rules, messages, and cross-field logic
Simple validations (as strings)
This is the most concise way to validate a field. You just list built-in rule names:
{
"component": "text",
"label": "Email",
"validations": ["required", "email"]
}
If the value is missing or not an email, the field will show an error.
Available string validations
| Rule | Description |
|---|---|
required | Must not be empty |
date_format | Must be a valid date |
only_int | Only integer numbers allowed |
only_letter | Only letters allowed |
only_int_price | Integer price format only |
email | Valid email address |
required_email | Required and must be a valid email |
niss | Valid NISS (national ID) |
iban | Valid IBAN |
required_tile | An item must be selected on the tile input |
phone_number | Valid phone number |
required_phone_number | Required and must be a valid phone number |
You can combine several in a single array.
Advanced validations (as objects)
Use objects if you need:
- Custom error messages
- Comparisons against another field
- Conditional validations
- Regex patterns
- Type coercion or derived values (like
age)
Example: exact match
{
"value": "MyCompany",
"message": "The company name must be MyCompany",
"assertion": "equal"
}
Example: number comparison
{
"value": 17,
"message": "Minimum 18 years",
"assertion": "isAbove"
}
Using expectation instead of assertion
{
"value": 17,
"message": "Minimum 18 years",
"expectation": "to.be.above"
}
Compare to another field
{
"value": { "from": "age" },
"message": "You cannot have more experience than your age",
"expectation": "to.be.below"
}
Validate based on another property’s existence
{
"property": { "from": "age" },
"message": "You have to define your age first",
"assertion": "exist"
}
Regex-based validation
{
"regex": {
"pattern": "^[A-Z0-9]+$",
"flags": "i",
"must_match": true
},
"message": "Only uppercase letters and numbers allowed"
}
- If
must_matchistrue: value must match the regex - If
false: value must not match the regex
Combining multiple conditions with operator
You can combine multiple object validations and control how they’re evaluated:
{
"assertion": "exists",
"message": "Name is required",
"operator": "or"
},
{
"assertion": "isEmpty",
"message": "Name is required",
"operator": "or"
}
Currently, you cannot nest condition groups — everything is evaluated flatly.
propertyAs: Force a type or interpretation
Sometimes you want to compare a value as a number, or as an age, or as duration since a date.
Use propertyAs to convert types at runtime.
Available coercion values
stringnumberboolage(years since date)years,months,daysyearsFrom,monthsFrom,daysFrom
Example: compare derived age
{
"property": "date_of_birth",
"propertyAs": "age",
"value": 30,
"assertion": "isBelow",
"message": "The age must be below 30 years"
}
Example: duration from another date
{
"fromDate": "first_date",
"propertyAs": "yearsFrom",
"value": 17,
"assertion": "isAbove",
"message": "Min 17 years from above date"
}
Conditional validations
A validation can also be enabled only if a condition is met:
{
"assertion": "exists",
"message": "Name is required",
"conditions": [
{
"property": { "from": "name_is_required" },
"assertion": "isTrue"
}
]
}
This validation only runs if name_is_required is true.
Storybook examples
For assertion syntax, see Conditions