Skip to content

Options

The options prop accepts a TelInputOptions object. All fields are optional — omitted fields use their defaults.

<TelInput
options={{
autoPlaceholder: true,
spaces: true,
validateOn: 'always'
}}
/>
OptionTypeDefaultDescription
autoPlaceholderbooleantrueGenerates a country-specific placeholder. E.g. for US: 201 555 0123. Overridden by the placeholder prop.
spacesbooleantrueWhen true, the input displays detailedValue.formattedNumber (spaces-only format, e.g. 215 456 7890). When false, shows raw digits without any separators.
validateOn'input' | 'blur' | 'always''always'Controls when validation runs. See below.
allowedCountriesCountryCode[]undefinedRestrict to a set of countries. Numbers from other countries are marked invalid with 'COUNTRY_NOT_ALLOWED'.
lockCountrybooleanfalsePrevent the country from changing when the user types a different dial code.

Validates on every keystroke and on blur. The valid prop updates in real-time.

Validates on every keystroke only.

Validates only when the input loses focus. No red/invalid state flashing during typing — best for forms.

Restrict which countries are considered valid:

<TelInput
options={{ allowedCountries: ['US', 'CA', 'GB'] }}
bind:value
bind:valid
bind:validationError
/>
<!-- If user types +49... (Germany), valid = false, validationError = 'COUNTRY_NOT_ALLOWED' -->

Prevent the country from switching when the user types a different dial code:

<script>
let country = $state('US');
</script>
<TelInput
bind:country
options={{ lockCountry: true }}
/>
<!-- Typing +44 will NOT switch to GB — country stays US -->

spaces is reactive — change it and the displayed value reformats instantly:

<script>
let opts = $state({ spaces: true });
</script>
<label>
<input type="checkbox" bind:checked={opts.spaces} />
Spaces
</label>
<TelInput options={opts} />
import type { TelInputOptions } from 'svelte-tel-input/types';
const options: TelInputOptions = {
autoPlaceholder: true,
spaces: true,
validateOn: 'blur',
allowedCountries: ['US', 'HU'],
lockCountry: false
};