Choose your stack
validonce has two halves. On the server you write cross-field rules in your own language, and validonce
exports them into your OpenAPI document under x-validonce. In the browser a small runtime reads those rules
and checks the form before it is sent. The server still checks every request.
1. Pick your server
Each tab shows the same four rules for the playground's Contact form: email or phone, a full address or none of it, a postal code when the country is US, and an end date on or after the start date. Pick a tab once and every code sample on this site follows it.
- ASP.NET Core
- FastAPI
- Fastify
- NestJS
- Go
- Spring Boot
public sealed class ContactValidator : ValidonceValidator<Contact>
{
private static readonly string[] Countries = ["US", "CA", "GB", "other"];
public ContactValidator()
{
// Rule order is part of the contract (examples/CONTRACT.md).
AtLeastOneOf(x => x.Email, x => x.Phone).WithMessageKey("rules.contact_email_or_phone");
AllOrNone(x => x.Street, x => x.City, x => x.PostalCode).WithMessageKey("rules.address_all_or_none");
RequiredWhen(x => x.PostalCode, If.Eq(x => x.Country, "US")).WithMessageKey("rules.postal_code_required_us");
Compare(x => x.AvailableTo, CompareOp.Ge, x => x.AvailableFrom).WithMessageKey("rules.available_to_after_from");
RuleFor(x => x.Email).EmailAddress().When(x => !string.IsNullOrEmpty(x.Email));
RuleFor(x => x.Phone).Matches(@"^\+?[0-9 ()-]{7,20}$").When(x => !string.IsNullOrEmpty(x.Phone));
RuleFor(x => x.Country).NotEmpty().Must(c => c is null || Countries.Contains(c)).WithMessage("Country must be one of US, CA, GB, other.");
}
}
From examples/aspnet-app/Signup.cs, the example app that runs in the playground.
class Contact(ValidonceModel):
# Field names are the wire names (see examples/CONTRACT.md).
email: str | None = Field(default=None, json_schema_extra={"format": "email"})
phone: str | None = Field(default=None, pattern=r"^\+?[0-9 ()-]{7,20}$")
street: str | None = None
city: str | None = None
postalCode: str | None = None # noqa: N815
country: Literal["US", "CA", "GB", "other"]
availableFrom: date | None = None # noqa: N815
availableTo: date | None = None # noqa: N815
# Order is part of the contract.
__rules__ = [
at_least_one_of(F.email, F.phone, key="rules.contact_email_or_phone"),
all_or_none(F.street, F.city, F.postalCode, key="rules.address_all_or_none"),
when(F.country == "US").require(F.postalCode, key="rules.postal_code_required_us"),
F.availableTo.ge(F.availableFrom, key="rules.available_to_after_from"),
]
From examples/fastapi-app/app.py, the example app that runs in the playground.
const contactRules = defineRules(
"Contact",
[
atLeastOneOf(C.email, C.phone, { key: "rules.contact_email_or_phone" }),
allOrNone(C.street, C.city, C.postalCode, { key: "rules.address_all_or_none" }),
when(C.country.eq("US")).require(C.postalCode, { key: "rules.postal_code_required_us" }),
C.availableTo.ge(C.availableFrom, {
key: "rules.available_to_after_from",
type: "date",
}),
],
{ fields: contactFields },
);
From examples/fastify-app/src/app.ts, the example app that runs in the playground.
const contactRules = defineRules(
"Contact",
[
atLeastOneOf(C.email, C.phone, { key: "rules.contact_email_or_phone" }),
allOrNone(C.street, C.city, C.postalCode, { key: "rules.address_all_or_none" }),
when(C.country.eq("US")).require(C.postalCode, { key: "rules.postal_code_required_us" }),
C.availableTo.ge(C.availableFrom, {
key: "rules.available_to_after_from",
type: "date",
}),
],
{ fields: contactFields },
);
From examples/nestjs-app/src/app.ts, the example app that runs in the playground.
var contactRules = validonce.MustBuild[Contact](
validonce.AtLeastOneOf([]string{"email", "phone"},
validonce.Key("rules.contact_email_or_phone"), validonce.ID("Contact.at_least_one_of.email")),
validonce.AllOrNone([]string{"street", "city", "postalCode"},
validonce.Key("rules.address_all_or_none"), validonce.ID("Contact.all_or_none.street")),
validonce.When(validonce.Eq("country", "US")).Require("postalCode",
validonce.Key("rules.postal_code_required_us"), validonce.ID("Contact.required_when.postalCode")),
validonce.Cmp("availableTo").Ge(validonce.Ref("availableFrom"),
validonce.Key("rules.available_to_after_from"), validonce.ID("Contact.compare.availableTo")),
)
From examples/go-app/contact.go, the example app that runs in the playground.
public final class ContactRules extends RuleDefinition<Contact> {
public ContactRules() {
super(Contact.class);
}
@Override
protected void define(RuleSetBuilder<Contact> r) {
r.atLeastOneOf("email", "phone").key("rules.contact_email_or_phone")
.allOrNone("street", "city", "postalCode").key("rules.address_all_or_none")
.requiredWhen("postalCode", Condition.eq("country", "US")).key("rules.postal_code_required_us")
.compare("availableTo", Op.GE, "availableFrom").key("rules.available_to_after_from");
}
}
From examples/spring-app/src/main/java/com/metatoy/validonce/example/ContactRules.java, the example app that runs in the playground.
Then follow the guide for your server:
| Server | Guide |
|---|---|
| ASP.NET Core (FluentValidation) | Getting started: ASP.NET Core |
| FastAPI (Pydantic) | Getting started: FastAPI |
| Fastify (TypeBox) | Getting started: Fastify |
| NestJS (class-validator) | Getting started: NestJS |
| Go (Huma or go-playground/validator) | Getting started: Go |
| Spring Boot (Java or Kotlin) | Getting started: Spring Boot |
| Kubernetes CRDs (CEL) | Kubernetes |
2. Pick your client
| Client | Guide |
|---|---|
| React (react-hook-form and Zod) | React client |
| Angular (Signal and Reactive Forms) | Angular client |
| Vue (VeeValidate) | Vue client |
| Plain forms and web components | DOM client |
| Generated clients (Hey API, kubb, orval) | Client codegen |
3. See it run
- Rule kinds, live: each of the five rule kinds as a small form, running the real runtime in this page.
- The playground: any server with any client, with the server's answer next to the form's.
- Moving an existing app over? Agentic migration covers the MCP server and the migration skill.