shadcn.io is not affiliated with official shadcn/ui
Form examples · Basic Forms
Password Input Form for React
A form with one password input that needs at least 8 characters before it continues.
Weak passwords put accounts at risk. This form asks for a password of at least 8 characters with Zod, and type="password" masks what's typed. A Controller connects the Input to React Hook Form inside a Field, with a FieldDescription for the requirement and a FieldError for "Password must be at least 8 characters." Use it in sign-up flows, password resets or security settings.
Preview
Installation
FAQ
What password does this form accept?
password is z.string().min(8, "Password must be at least 8 characters."). There is no letter, number or symbol check; see the password strength example for those.
How is the password hidden?
The Input sets type="password", so the browser masks it. The typed string is still what React Hook Form stores. The placeholder is eight asterisks.
Where are the requirements written?
FieldDescription says "Must be at least 8 characters long." When submit fails the minimum, the Field gets invalid and FieldError shows "Password must be at least 8 characters."
How is the field registered?
useForm takes zodResolver(formSchema) and defaultValues of password: "". The Controller with name="password" spreads field onto the Input. FieldLabel htmlFor matches the input's id, password-input-form-password.
Related
- Password Strength Validation FormA password that needs 8 characters with
- Email Input FormA newsletter form with one email input
- Simple Text Input FormA form with one username text input that
- Password with Toggle InputA password field with a button that shows
- Login FormA login form with a welcome heading
- Signup FormA sign-up form with full name, email, a