Raw value: 4242424242424242
Cents: 4999
The CLI also installs the npm packages and registry items it builds on, and reads the style in your components.json to pick the Base UI or Radix build.
import { CurrencyInput, MaskedInput } from "@/components/ui/masked-input"
import { Label } from "@/components/ui/label"
export function PaymentFields() {
return (
<div className="grid gap-3">
<div className="grid gap-1.5">
<Label htmlFor="card">Card number</Label>
<MaskedInput id="card" mask="#### #### #### ####" placeholder="4242 4242 4242 4242" />
</div>
<div className="grid gap-1.5">
<Label htmlFor="price">Amount</Label>
<CurrencyInput id="price" currency="USD" locale="en-US" defaultValue={4999} />
</div>
</div>
)
}MaskedInput
Input that formats typed characters according to a mask pattern while storing the raw unmasked value.
| Prop | Type | Default |
|---|---|---|
maskRequiredstringMask pattern where # matches digits, a or A matches letters, and * matches alphanumeric characters. | string | |
definitionsRecord<string, RegExp>Custom character token definitions mapping token character to matching RegExp pattern. | Record<string, RegExp> | |
valuestringControlled unmasked raw string. | string | |
defaultValuestringDefault""Initial value when uncontrolled. | string | "" |
onValueChange(value: string, formattedValue: string) => voidCalled with the unmasked and formatted values. | (value: string, formattedValue: string) => void | |
namestringSubmits the raw unmasked string via a hidden input. | string | |
disabledbooleanDisables the input. | boolean |
Other props go to the <input>.
CurrencyInput
Input that formats monetary amounts according to currency and locale while storing integer cents.
| Prop | Type | Default |
|---|---|---|
currencystringDefault"USD"ISO 4217 currency code (e.g. USD, EUR, JPY, GBP). | string | "USD" |
localestringDefault"en-US"BCP 47 language tag for number and currency formatting. | string | "en-US" |
valuenumber | nullControlled amount in integer cents. | number | null | |
defaultValuenumber | nullDefaultnullInitial value when uncontrolled. | number | null | null |
onValueChange(value: number | null, formattedValue: string) => voidCalled with integer cents and formatted text. | (value: number | null, formattedValue: string) => void | |
minnumberMinimum allowed amount in cents. Enforced on blur. | number | |
maxnumberMaximum allowed amount in cents. Enforced during typing and on blur. | number | |
namestringSubmits the integer cents via a hidden input. | string | |
disabledbooleanDisables the input. | boolean |
Other props go to the <input>.
Currency formatting
Localized currencies format symbols and decimal separators automatically while storing integer cents.