Skip to content

remote

Validates a field by sending its value to a remote server and checking the response.

Options

OptionTypeDefaultDescription
urlstringrequiredURL to send the validation request to
method"GET" | "POST""GET"HTTP method
dataRecord<string, string>{}Additional data to send with the request
headersRecord<string, string>{}Additional request headers
messagestringlocale defaultCustom error message

Playground

The playground below uses the promise validator to simulate remote validation because a real server endpoint is unavailable in the browser sandbox. For actual usage, see the remote configuration example below.

Real remote validator configuration

js
validare(form, {
  fields: {
    email: {
      validators: {
        remote: {
          url: '/api/validate-email',
          method: 'POST',
          message: 'Email is already registered',
        },
      },
    },
  },
});

Valid values

ValueNotes
Server returns { "valid": true }Validation passes

Invalid values

ValueReason
Server returns { "valid": false }Validation fails
Server returns { "valid": false, "message": "Email taken" }Fails with server-provided message

Notes

  • Empty string ("") always returns valid: true — validators only run on non-empty values. Combine with notEmpty to require a value.
  • The server must return JSON: { "valid": true } or { "valid": false, "message": "..." }.
  • For GET requests, the field value is appended as a query parameter.
  • Use Sequence plugin to avoid sending requests until basic format validators pass.

Released under the MIT License.