Forms

Phone input

A phone number field for any country. Pick or search a country, and the number formats as you type. Paste a full international number and the country follows. It says plainly when a number doesn't look right.

Installation

npx sinaui add phone-input

Examples

Countries you choose first

preferred puts a few countries at the top of the list. Search by name, code (BD) or dialling code (+880).

We'll text you when your manuscript is ready to collect.

Nothing saved yet

<script lang="ts">
	import PhoneInput from '#lib/ui/PhoneInput.svelte';

	let value = $state('');
</script>

<PhoneInput
	label="Phone"
	country="BD"
	preferred={['BD', 'MY', 'SA', 'TR']}
	hint="We'll text you when your manuscript is ready to collect."
	bind:value
/>
<p class="out">{value ? `Saved as ${value}` : 'Nothing saved yet'}</p>

<style>
	.out {
		margin: 0.75rem 0 0;
		color: var(--ui-muted);
		font-size: 0.875rem;
		font-variant-numeric: tabular-nums;
	}
</style>

In a form

With name, the form sends the full international number. Submitting an empty or wrong number stops the form and shows why.

<script lang="ts">
	import Button from '#lib/ui/Button.svelte';
	import PhoneInput from '#lib/ui/PhoneInput.svelte';

	let sent = $state('');
</script>

<form
	onsubmit={(e) => {
		e.preventDefault();
		sent = String(new FormData(e.currentTarget).get('phone'));
	}}
>
	<PhoneInput label="Phone for the reading room" name="phone" country="TR" required />
	<Button type="submit">Book a desk</Button>
	<p class="out" role="status">{sent ? `Would send phone=${sent}` : ''}</p>
</form>

<style>
	form {
		display: grid;
		justify-items: start;
		gap: 0.75rem;
	}
	form > :global(.field) {
		justify-self: stretch;
	}
	.out {
		margin: 0;
		color: var(--ui-muted);
		font-size: 0.875rem;
		font-variant-numeric: tabular-nums;
	}
</style>

Your own error

error replaces the built-in messages, for problems only your server knows about.

This number is already on another library card.

<script lang="ts">
	import PhoneInput from '#lib/ui/PhoneInput.svelte';
</script>

<PhoneInput
	label="Phone"
	value="+60312345678"
	error="This number is already on another library card."
/>

Props

PropTypeDefault
labelstring (required)
valuestring (bindable): the number as +8801712345678, empty until valid''
validboolean (bindable)false
countrystring (bindable): a country code like 'BD'from the browser's language
preferredstring[]: listed first[]
namestring: sent with forms
requiredbooleanfalse
disabledbooleanfalse
placeholderstring
hintstring
errorstring: replaces the built-in messages

Keyboard

KeyDoes
โ†“ โ†‘ on the countryOpen the country list
Typing in the listSearch by name, code or dialling code
โ†“ โ†‘ Page Up Page DownMove through countries
EnterChoose the country and go back to the number
EscapeClose the list

Accessibility

  • The country button is named with the country and its dialling code.
  • The number field has its label; hints and errors are read out with it.
  • Messages appear when you leave the field or submit, not while you're still typing.
  • When a pasted number changes the country, the new country is announced.
  • The number always reads left to right, including in right-to-left pages.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme