callback
Validates a field using a custom synchronous function.
Options
| Option | Type | Default | Description |
|---|---|---|---|
callback | (input: ValidatorInput) => { valid: boolean, message?: string } | required | Custom validation function |
message | string | locale default | Custom error message |
Playground
Valid values
| Value | Notes |
|---|---|
Callback returns { valid: true } | Validation passes |
Invalid values
| Value | Reason |
|---|---|
Callback returns { valid: false } | Validation fails with default or inline message |
Notes
- Empty string (
"") always returnsvalid: true— validators only run on non-empty values. Combine withnotEmptyto require a value. - The
inputobject has:value(string),elements(HTMLElement[]),options(validator options),field(field name). - The callback can return
{ valid: false, message: 'Custom message' }to override the configured message. - For async operations, use
promiseinstead.