Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Form examples · Multi Field

Mixed Input Types Form for React

A registration form that mixes text, number, email and phone inputs, each with the validation its type needs.

Framework
UI library

Different data needs different inputs and different checks. This form uses a text input for the name, a number input for the age, an email input and a phone input, and one Zod schema validates each the way its type needs. The age reaches the form as a number, so the schema checks it with z.number(). Each field is a Field with its FieldLabel, Input and FieldError. Use it for registration, contact or onboarding forms.

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.

FAQ

Which input types are on this form?

Full Name is a text input, Age is type="number", Email is type="email" and Phone is type="tel", so phones show a fitting keyboard for each.

What do name, email, and phone check?

fullName needs 2 characters ("Name must be at least 2 characters."), email is z.email(…) ("Please enter a valid email address.") and phone matches a pattern ("Please enter a valid phone number.").

How is the age turned into a number?

The age input's onChange passes undefined for an empty box and Number(event.target.value) otherwise, and its value is field.value ?? "". The schema is z.number(…).min(18, …), so an empty or under-18 age shows "You must be at least 18 years old."

Which phone string passes?

PHONE_PATTERN is ^\+?[1-9]\d{1,14}$: an optional plus, then 2 to 15 digits, such as +15551234567. The placeholder +1 (555) 123-4567 has spaces and brackets, so typed that way it fails.

What order are the fields in?

Full Name, Age, Email, Phone, then Register, stacked in one FieldGroup. Each label's htmlFor matches its input's id, such as mixed-input-types-form-age.

What does onSubmit receive for age?

A number, such as 25, since the input already hands the form a number. form.handleSubmit(onSubmit) logs { age, email, fullName, phone } once every field passes.