# Shadcn Form Validation

> Number field in form

- Type: example, free and open source (MIT)
- Component: [Number Field](https://reui.io/components/number-field.md)
- Page: https://reui.io/components/number-field/c-number-field-6
- Docs (Base UI): https://reui.io/docs/components/base/number-field.md
- Docs (Radix UI): https://reui.io/docs/components/radix/number-field.md
- MCP: `get_example("c-number-field-6")`
- Registry item: https://reui.io/r/styles/base-nova/c-number-field-6.json
- Uses: Alert, Button, Field, Number Field

## Best for

A React Hook Form Controller binding the amount, with zod bounds, an error message and Cancel and Submit buttons

## Agent notes

- `onSubmit` only raises a `toast` with `data.amount` and resets the form; send the amount to your API there and mount the Sonner toaster
- `FormSchema` requires 10 to 100 while `NumberField` allows 0 to 100 and starts at 5; align `min` and `defaultValues` with the schema

## When not to use

- A standalone control outside any schema or submit flow: use [Default Size](https://reui.io/components/number-field/c-number-field-1.md) (`get_example("c-number-field-1")`)

## Third-party libraries

- Sonner v2: [API reference](https://sonner.emilkowal.ski/toast), [docs](https://sonner.emilkowal.ski/getting-started)
- React Hook Form v7: [API reference](https://react-hook-form.com/docs), [docs](https://react-hook-form.com/get-started)
- React Hook Form resolvers v5: [API reference](https://github.com/react-hook-form/resolvers#api), [docs](https://github.com/react-hook-form/resolvers)
- Zod v4: [API reference](https://zod.dev/api), [docs](https://zod.dev/)

## Install

```bash
npx shadcn@latest add @reui/c-number-field-6
```

## About Shadcn Number Field

### When to use

- Quantities, amounts and counts stepped up or down by buttons inside a min and max range
- Compact numeric settings whose label scrubs the value when dragged sideways
- Validated amounts in a React Hook Form form, checked by a zod schema with the error shown below

### When not to use

- Free text such as a name, an email or an order ID, with nothing to step: use [Input](https://reui.io/components/input.md) (`get_component("input")`)
- A full plans comparison with tier prices and a seat count to adjust: use the [Pricing blocks](https://reui.io/blocks/marketing/pricing.md)
- A record entry page with many controls, such as a product with price and stock: use the [Form blocks](https://reui.io/blocks/application/form.md)

### Agent notes

- `onValueChange` receives null when the input is cleared, so type a controlled `value` as a number or null
- Set `aria-invalid` on `NumberFieldGroup` to turn its border destructive; a shadcn `Field` marked invalid only recolors text
- An outside label must point `htmlFor` at the `id` passed to `NumberField`, which Base UI sets on the input

Every ReUI item has a twin like this one; the index is https://reui.io/llms.txt. Agents with the ReUI MCP (https://reui.io/docs/mcp) get the same guidance from the getters named above.
