Skip to content

callback

Validates a field using a custom synchronous function.

Options

OptionTypeDefaultDescription
callback(input: ValidatorInput) => { valid: boolean, message?: string }requiredCustom validation function
messagestringlocale defaultCustom error message

Playground

Valid values

ValueNotes
Callback returns { valid: true }Validation passes

Invalid values

ValueReason
Callback returns { valid: false }Validation fails with default or inline message

Notes

  • Empty string ("") always returns valid: true — validators only run on non-empty values. Combine with notEmpty to require a value.
  • The input object 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 promise instead.

Released under the MIT License.