Introduction
@silver-formily/validator is the validation core maintained by Silver Formily. It turns declarative rule descriptions into executable validation pipelines and normalizes output into error, warning, and success message buckets.
The package is built around four pieces:
- A
validateentry that executes one or many validation descriptions. - A default ruleset for
required,min,max,pattern,format, and related constraints. - A registry layer for custom rules, formats, locales, and template engines.
- A parser layer that normalizes strings, functions, and rule objects into runnable validators.
Installation
bash
pnpm add @silver-formily/validatorbash
npm install @silver-formily/validatorExample
ts
import { validate } from '@silver-formily/validator'
const result = await validate('', [
{ required: true },
{ minLength: 3, message: 'Please enter at least 3 characters' },
])
result.error
// ['The field value is required', 'Please enter at least 3 characters']When to use it
- You need a stable validation engine behind form or schema rules.
- You want to add project-specific rules or formats.
- You need locale-aware validation messages.
- You need template-driven message rendering with runtime context.