easy-forms
Validation

Extending validators

Register your own reusable named validator rules via module augmentation.

Beyond custom, you can teach the type system about your own reusable validator rules so they're available — and type-checked — across every schema.

Augment the registry

declare module '@easy-forms/core' {
	interface ValidatorRegistry {
		creditCard?: boolean;
		stronger?: { minScore: number };
	}
}

Now validators: { creditCard: true } is valid and typed wherever you author a schema.

{
	key: 'card',
	label: 'Card number',
	control: 'text',
	validators: { required: true, creditCard: true },
}

Wire up the implementation

Provide the runtime behavior for your registered rule when you configure validation in your app (alongside the built-in validators). Pair this with a custom validator if you want to keep the logic inline, or centralize it so every schema benefits.

This is the same module-augmentation pattern used to add custom control types and custom dependency kinds — extend the library without forking it.