Custom Validation
Beyond the built-in validation options, you can create custom validation rules.
Custom Validation Messages
Customize error messages for standard validations:
- Select a component
- Go to the Validation tab
- Enable the desired validation (required, pattern, etc.)
- Enter a custom error message
Regular Expression Validation
Use regular expressions for pattern matching:
- Select a component
- Go to the Validation tab
- Enable Regular Expression Pattern
- Enter a regular expression pattern
- Provide a custom error message
Example patterns:
- Email:
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ - Phone:
^\+?[0-9]{10,15}$ - Alphanumeric:
^[a-zA-Z0-9]+$ - Malaysian ID:
^[0-9]{6}-[0-9]{2}-[0-9]{4}$
Custom JavaScript Validation
For complex validation scenarios, use custom JavaScript:
- Select a component
- Go to the API tab (Technical Properties)
- In the Custom Validation field, enter JavaScript
- Return
truefor valid input or an error message string for invalid input
Example: Validate that a date is a weekday:
const date = new Date(input);
const day = date.getDay();
if (day === 0 || day === 6) {
return 'Please select a weekday';
}
return true;
Cross-Field Validation
Validate fields in relation to each other:
- Use custom JavaScript validation
- Reference other fields using
data.fieldKey
Example: Validate that an end date is after a start date:
const startDate = new Date(data.startDate);
const endDate = new Date(input);
if (endDate <= startDate) {
return 'End date must be after start date';
}
return true;