Skip to content

Validation

Overview

mobx-react-form ships with a pluggable validation system. You can choose one or more validation backends (called drivers) and attach them to the form at initialization. Each driver is responsible for validating each field and pushing error messages into the field's validationErrorStack.

Validation can be triggered:

  • Automatically — on field blur, change, form init, submit, clear, reset (configurable via options)
  • Manually — via form.validate(), field.validate(), or form.submit()

For a deeper dive into the validation lifecycle (what happens when, in what order), see the Validation Lifecycle page.


Choosing a Validation Plugin

StyleDriverBest ForExample
Custom functionsVJFFull control, custom logic, server checks({ field }) => [field.value.length > 3, 'Too short']
Declarative rulesDVRSimple string-based rules (like Laravel)'required or email or min:5'
JSON SchemaSVKJSON-first projects, API compatibility{ type: 'string', minLength: 3 }
Object schemaYUPModern JS/TS, chainable APIy.string().required().min(3)
Object schemaJOIEnterprise-grade, rich error messagesj.string().min(3).required()
TypeScript schemaZODTypeScript-first, type inferencez.string().min(3)

When to use what

Use CaseRecommended
Simple forms with basic rulesDVR — fastest to write
Full control over validation logicVJF — write any function
JSON Schema compliance (API validation)SVK — standards-based
Modern object-oriented validationYUP — popular, good DX
Enterprise / complex schemasJOI — battle-tested, rich errors
TypeScript-native with inferZOD — best TS integration

Can I use multiple plugins?

Yes. You can enable multiple plugins simultaneously. Validation runs through all enabled drivers in sequence (configurable via validationPluginsOrder). If stopValidationOnError is true, subsequent drivers are skipped once a field has an error.


Plugin Comparison

FeatureVJFDVRSVKYUPJOIZOD
Custom validation functions✅ Native
String-based rules
JSON Schema
Chainable API
Async validation
Extend with custom rules
Automatic error messagesUser-defined
TypeScript inferenceNoNoNoPartialPartial

VJF, DVR and SVK support async validation and custom extension (via the extend callback). YUP, JOI and ZOD do not support the extend callback or async validation pipelines — they rely on their own native APIs for those features.


Setup Pages

Choose your plugin

Extend with custom rules

Available only for VJF, DVR and SVK.

Async validation

Available only for VJF, DVR and SVK.


Released under the MIT License.