Introduction
@silver-formily/validator is the validation core for Silver Formily. It turns declarative field rules into executable validation flows and produces consistent error, warning, and success feedback.
Where to start
- Configure field rules in Formily: read Quick Start
- Look up
validate(), built-in rules, and formats: read Run Validation - Register global rules, formats, and locales: read Registry and Configuration
- Build a form adapter or inspect the parsing process: read Rule Parsing
Most application development only needs Quick Start and the rule reference in Run Validation.
What it includes
The package mainly provides:
- Built-in rules such as
required,min,max,pattern, andformat. - Custom synchronous or asynchronous validators, with error, warning, and success feedback.
- Global registration for rules, formats, locales, and message template engines.
- The
validate()and rule parsing APIs used by Formily and other upper layers.
Install directly
Formily projects normally receive validator capabilities indirectly through @silver-formily/core. Install this package directly only when you need to use it independently or build an adapter:
bash
pnpm add @silver-formily/validatorbash
npm install @silver-formily/validatorStandalone usage
Outside Formily, call validate() directly:
ts
import { validate } from '@silver-formily/validator'
const result = await validate('', [
{ required: true },
{ minLength: 3, message: 'Enter at least 3 characters' },
])
result.error
// ['The field value is required']See Run Validation for the complete parameters and return value.