WebberUI

Taiwan Phone Input

Mobile numbers starting with 09 are formatted automatically as 09xx-xxx-xxx, with landline and mobile detected automatically.

A Taiwan phone number input: hyphens are inserted as you type (0912-345-678), numbers starting with 09 are detected as mobile and those starting with 0X as landline, grouped by the length of the area code (02-2712-3456). The leading icon switches with the type, an invalid prefix is flagged in red immediately, and pasting a string containing +886, full-width digits, or other noise is cleaned automatically.

Loading preview…
npx shadcn@latest add https://webberui.com/r/taiwan-phone-input.json

Playground

Tune the props live — the code snippet updates as you go, so you can dial in the look you want before copying it.

<TaiwanPhoneInput />

Installation

npx shadcn@latest add https://webberui.com/r/taiwan-phone-input.json

Or, once registries are configured in components.json, install it as @webberui/taiwan-phone-input.

Usage

import { TaiwanPhoneInput } from "@/components/ui/taiwan-phone-input";

const [phone, setPhone] = React.useState("");

<TaiwanPhoneInput value={phone} onChange={setPhone} allowLandline />

onChange returns the cleaned digits (for example 0912345678), ready to store directly in a database; the hyphenated display format is handled inside the component. You can also use the exported normalizeTaiwanPhone and analyzeTaiwanPhone helper functions to clean and validate outside the component.

The landline area code table includes every current long-distance area code (02–08, 037, 049, 082, 089, 0836), matched longest-area-code-first. Some area codes mix 7- and 8-digit subscriber numbers in practice; the component demonstrates the common length, so extend the built-in lookup table if you need more precision.

Props

PropTypeDefaultDescription
valuestringControlled value: the phone number (it may contain noise, which is cleaned to digits internally)
onChange(digits: string) => voidFires when the value changes, returning the cleaned digits-only string
allowLandlinebooleantrueWhether landlines (0X area codes) are accepted; false accepts only mobile numbers starting with 09
placeholderstringdepends on allowLandlinePlaceholder text
disabledbooleanfalseDisable the input
namestringForm field name; the digits are submitted through a hidden field
idstringThe input element's id, for binding an external label
classNamestringForwarded to the outermost container

Accessibility

  • It uses type="tel", inputMode="tel", and autoComplete="tel", so mobile devices bring up the numeric keypad automatically and autofill works
  • aria-invalid is set when validation fails, and the error and success messages sit in an aria-live="polite" region so they are read out immediately
  • The decorative type icon and status icon are both marked aria-hidden and do not interfere with assistive technology
  • When the user has "reduce motion" enabled at the system level, the icon switch, the green check pop, and the message expansion animations are disabled
  • When editing mid-string, the caret position is restored correctly after reformatting and does not jump to the end of the line

On this page