Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

Multiple Validation Messages Input for React

A Password field set to pass, marked invalid, with three fixed messages: too short, no number, and no special character.

Password shows pass and the border is in the error color. Under it, a fixed list of three messages, each with an alert icon: too short, no number, and no special character.

Use it after a check that failed more than one rule, so people see every problem at once. A single banner is a weaker Alert. In React, Base UI does not test this password.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.
Use email insteadNo credit card

Anatomy

Input anatomy: input, placeholder, value, caret

Usage

<Field className="w-full max-w-sm" invalid>
  <FieldLabel htmlFor="multiple-password">Password</FieldLabel>
  <Input
    className="bg-background"
    defaultValue="pass"
    id="multiple-password"
    placeholder="Enter password"
    type="password"
  />
  <FieldError className="flex flex-col gap-1">
    {messages.map((message) => (
      <span className="flex items-center gap-2" key={message}>
        <CircleAlertIcon aria-hidden="true" className="size-4 shrink-0" />
        {message}
      </span>
    ))}
  </FieldError>
</Field>

FAQ

How are the messages listed?

One FieldError holds the messages, stacked with flex-col gap-1. Each is a row with a CircleAlertIcon and its text, rendered from a static list of strings.

How is the field marked invalid?

invalid on Field, which sets aria-invalid on the input and gives it a destructive border and ring.

Are the rules checked as I type?

No. The value pass and the messages are fixed, to show the invalid state. Compute the list from the value to make it live, as the Real-time Validation example does.

Are the icons read out?

No. Each CircleAlertIcon has aria-hidden; the text carries the message.

Should I show all rules up front instead?

For passwords, a checklist that ticks off as people type, like the Real-time Validation example, is friendlier than errors after the fact. Use a list of errors when the value comes from elsewhere or is checked on submit.

How is Password tied to the field?

Clicking the label focuses the field, and screen readers announce it with the field. FieldLabel sets htmlFor to multiple-password, the input's id.

API Reference

Field

Sets invalid and htmlFor="multiple-password". The rest is on the Field page.

Input

Sets defaultValue="pass", id="multiple-password", placeholder="Enter password" and type="password". The rest is on the Input page.