Skip to Content

Live example

A form that validates with the generated Valibot and Zod schemas.

The forms come from one .proto message. Select a form library, submit an empty form to see the messages, then switch the language.

With react-hook-form and TanStack Form, the left form validates with the generated Valibot schema, and the right form with the generated Zod schema. Formisch takes a Valibot schema, so it shows one form.

Valibot

Zod

What to try

  • Tags. Enter a,a. repeated.unique has no standard action, so both libraries show their generic message.
  • Points. Enter abc. The value cannot convert to a bigint, so the schema reports a type issue.
  • Contact. Select Phone and enter 123. The oneof case has its own pattern rule.
  • Language. Switch to ja after a failed submit. The messages of both libraries change.

A valid submit passes the values to create() and shows the CreateUserRequest message as JSON.

The rules

user.proto
message CreateUserRequest {
  string name = 1 [(buf.validate.field).string = {min_len: 1, max_len: 20}];
  string email = 2 [(buf.validate.field).string.email = true];
  optional int32 age = 3 [(buf.validate.field).int32 = {gte: 0, lt: 150}];
  Role role = 4 [(buf.validate.field).enum = {defined_only: true, not_in: [0]}];
  repeated string tags = 5 [(buf.validate.field).repeated = {
    max_items: 3
    unique: true
    items: {string: {min_len: 1}}
  }];
  int64 points = 6 [(buf.validate.field).int64 = {gte: 0, lte: 1000}];

  oneof contact {
    string phone = 7 [(buf.validate.field).string.pattern = "^[0-9]{2,4}-[0-9]{2,4}-[0-9]{4}$"];
    string slack = 8 [(buf.validate.field).string.prefix = "@"];
  }

  bool agreed = 9 [(buf.validate.field).bool.const = true];
}

The source is in examples/react-forms. Each form library has a guide: react-hook-form, TanStack Form, and Formisch.