CurrencyInput
A money field that fills from the right like a cash register, so the caret can never drift into the middle of a number. Separators, symbol placement and the number of fraction digits come from Intl for the active locale and currency, including zero-decimal currencies such as JPY. The value is an integer count of minor units, so no float ever touches a price.
$ npx shadcn@latest add https://input-cn.vercel.app/r/currency-input.jsonHand this to Claude Code
Most people reach this component through an agent rather than by reading the page. Pick how you want it wired and take a prompt that already carries the canonical value, the real prop names and the mistakes worth avoiding.
Nothing runs on its own. The link opens the tool with the prompt typed into the box; you read it and press Enter. If the button does nothing, Claude Code is not installed on this machine — use Copy prompt instead.
Live demo
Digits fill from the right, like a register.
value = 0 · minor units
Constraints
Validation rules, declared as props. Each one produces its own message and its own data-rule value, so a test can assert the rule rather than the sentence.
Props
Shared props
Implemented identically by all eleven components. These tables are generated from the source interfaces at build time, so a renamed prop changes this page rather than quietly making it wrong.
With react-hook-form
import { useForm, Controller } from "react-hook-form"
import { zodResolver } from "@hookform/resolvers/zod"
import { moneySchema } from "@inputcn/currency/schema"
import { CurrencyInput } from "@/components/ui/currency-input"
import { z } from "zod"
// The companion schema validates the CANONICAL value, so the resolver and the
// field can never disagree about what "valid" means.
const schema = z.object({ price: moneySchema() })
export function Example() {
const { control } = useForm({ resolver: zodResolver(schema) })
return (
<Controller
name="price"
control={control}
render={({ field, fieldState }) => (
<CurrencyInput
label="Amount"
{...field}
aria-invalid={fieldState.invalid}
/>
)}
/>
)
}With a Server Action
import { CurrencyInput } from "@/components/ui/currency-input"
export default function Page() {
return (
<form action={save}>
<CurrencyInput name="price" label="Amount" />
<button>Save</button>
</form>
)
}
async function save(data: FormData) {
"use server"
// The hidden canonical input carries the real value, not the display text.
const price = Number(data.get("price")) // 129900
}Keyboard
Emits number, for example 129900. Keyboard operation is covered by automated tests; screen readers have not been verified yet.