Phone entry with real numbering metadata
Search countries, keep incomplete text editable and submit validated E.164 values. Numbering-plan validation does not verify ownership or send a message.
Keyboard
- Search the country field and use arrows and Enter to select.
- Type a national or international number; invalid text stays editable. Escape restores the committed number.
States covered
- metadata validation
- canonical E.164
- country search
- external native form
- prevented reset
- read only and disabled
Install this complete example and its component dependencies.
npx shadcn@latest add https://ui.bld8.dev/r/example-phone-country-form.jsonComplete source
/*!
MIT License
Copyright (c) 2026 Jaison
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import {useId,useState} from 'react';
import {Button,Checkbox,PhoneInput,UIProvider} from '@bld8/ui';
export default function PhoneForm(){const id=useId(),[prevent,setPrevent]=useState(false),[owned,setOwned]=useState<string|null>('+12025550123'),[reject,setReject]=useState(false),[result,setResult]=useState('No phone submitted.');return <UIProvider><div style={{display:'grid',gap:24,maxWidth:620}}>
<PhoneInput label="Contact phone" name="phone" form={id} required defaultCountry="AU" defaultValue="+61412345678" countries={['AU','US','GB','IN']} hint="National or international numbers; extensions are excluded."/>
<PhoneInput label="Host phone" name="owned" form={id} value={owned} onValueChange={next=>{if(!reject)setOwned(next);}} defaultCountry="US" countries={['AU','US','GB','IN']}/>
<PhoneInput label="Locked phone" name="locked" form={id} defaultValue="+61412345678" readOnly countries={['AU','US']}/>
<PhoneInput label="Disabled phone" name="disabled" form={id} defaultValue="+61412345678" disabled countries={['AU','US']}/>
<Checkbox label="Reject host phone edits" checked={reject} onCheckedChange={setReject}/><Checkbox label="Prevent phone reset" checked={prevent} onCheckedChange={setPrevent}/>
<form id={id} aria-label="Contact details" onReset={event=>{if(prevent)event.preventDefault();}} onSubmit={event=>{event.preventDefault();const data=new FormData(event.currentTarget);setResult('Phone: '+data.get('phone')+' | Owned: '+data.get('owned')+' | Locked: '+data.get('locked')+' | Disabled: '+data.has('disabled'));}}><div style={{display:'flex',gap:12,flexWrap:'wrap'}}><Button type="submit">Read phone values</Button><Button type="reset" variant="secondary">Reset phones</Button><Button variant="ghost" onClick={()=>setOwned(null)}>Clear host phone</Button></div></form><p role="status">{result}</p>
</div></UIProvider>;}