Field Validation
Configure validation rules to ensure data quality and guide respondents.
Overview
Every field can have validation rules that are checked when the user attempts to advance (in multi-step forms) or submit the form. Invalid fields display an error message below them and are highlighted in red. Validation rules are defined in the validation object inside each field definition.
Built-in Rules
| Property | Type | Default | Description |
|---|---|---|---|
| required | boolean | false | Field must have a non-empty value. |
| validation.minLength | number | — | Minimum character count for text fields. |
| validation.maxLength | number | — | Maximum character count for text fields. |
| validation.min | number | — | Minimum value for number/range fields. |
| validation.max | number | — | Maximum value for number/range fields. |
| validation.pattern | string | — | Regex the value must match. |
| validation.email | boolean | — | Validate as a valid email address format. |
| validation.url | boolean | — | Validate as a valid URL format. |
Custom Error Messages
Every validation rule can have a companion message property to replace the default error text:
"validation": {
"minLength": 8,
"minLengthMessage": "Password must be at least 8 characters",
"pattern": "^(?=.*[A-Z])(?=.*[0-9])",
"patternMessage": "Must contain at least one uppercase letter and one number"
}Regex Patterns
The validation.pattern property accepts any JavaScript-compatible regular expression string. Common patterns:
// Nepali postal code
"^\d{5}$"
// Alphanumeric only (no spaces)
"^[a-zA-Z0-9]+$"
// Strong password
"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$"
// URL slug
"^[a-z0-9]+(?:-[a-z0-9]+)*$"