Skip to content

MazInputPhoneNumber ​

MazInputPhoneNumber is a powerful and user-friendly component that helps users enter and validate phone numbers from any country with automatic formatting and validation

Before use it, you should install the MazUi plugin in your project, follow instructions in Getting Started

TIP

This component can be translated globally using the MazUi plugin.

✨ What makes this component special?

  • Smart country detection - Automatically detects country from browser locale or IP
  • Real-time validation - Visual feedback as you type
  • Auto-formatting - Formats numbers according to country standards
  • Search countries - Find countries quickly in the dropdown
  • Customizable - Full control over appearance and behavior
  • Accessible - Keyboard navigation and screen reader support
  • International - Supports all countries and phone formats

Basic Usage ​

The simplest way to use MazInputPhoneNumber - just add it and it works!

Phone number

Phone Number: Not entered yet

Country: Not selected

Is Valid: ❌ No

Country Management ​

Control which countries appear in the dropdown and their order.

Show your most common countries first
Limit to certain countries only
Remove unwanted countries

Layout Orientations ​

Choose how the country selector and phone input are arranged.

Phone number
Stacks on mobile, side-by-side on desktop
Phone number
Side-by-side on all screen sizes
Phone number
Stacked on all screen sizes

Display Options ​

Customize what information is shown to users.

Phone number
Display country names instead of calling codes
Phone number
Help users see the dialing codes
Phone number
Remove the example phone number hints (visible when the phone input is focused)
Phone number
Text-only country selection
Phone number
No request to flagcdn.com, works offline

Flags source ​

By default, the flags come from the flagcdn.com CDN. The flag-src prop, passed to the country selector, takes:

  • loadCountryFlag from maz-ui/country-flags: the flags of @maz-ui/icons, without any request to a third party, offline (hybrid apps with Capacitor or Cordova, PWAs);
  • a URL template of your own files: '/flags/{code}.svg' ({CODE} for uppercase codes);
  • your own function: (code) => string | undefined | Promise<string | undefined>.

Each flag is loaded only when visible, and a code without flag displays a badge. Set it once for the whole app with defaults.global.flagSrc of the MazUi plugin, or mazUi.flags of the Nuxt module ('local' or a URL template):

ts
import { loadCountryFlag } from 'maz-ui/country-flags'

app.use(MazUi, { theme: { preset: mazUi }, defaults: { global: { flagSrc: loadCountryFlag } } })

See MazSelectCountry for the details (bundle, Content Security Policy, PWA precache).

Smart Country Detection ​

Let the component automatically detect the user's country.

Browser Locale Detection

Uses browser language settings (enabled by default)

Phone number

IP-based Detection

Fetches country from user's IP address

Phone number

Manual Default Country

Set a specific default country

Phone number

Phone Number Formatting ​

Control how phone numbers are automatically formatted as users type.

Format on Blur (Default)

Shows raw input while typing, formats when field loses focus

Type freely, formats on blur

Format While Typing

Real-time formatting as you type

Formats as you type

Disable Formatting

For countries with multiple valid lengths or custom formatting

Raw input, no formatting

Validation States ​

Control the visual validation feedback and success/error indicators.

Hide Validation UI

No visual success/error indicators

Phone number

Force Success State

Always show success styling

Phone number

Force Error State

Always show error styling

Phone number

Internationalization ​

Make the component speak your users' language.

Custom Labels

Translate all text in the interface

Enter phone number

Country Names in French

Change the language of country names

Phone number

Custom Country Names

Override specific country names

Phone number

Custom Flag Styling ​

Replace the default flag emojis with your own design.

Country Code Badges

Show country codes instead of flags

Phone number

Custom Icons

Use your own flag icons or designs

Phone number

Advanced Configuration ​

Fine-tune the component for specific use cases.

Phone-only Mode

Hide country selector, pre-select country

US Phone Number

Custom Search Sensitivity

Adjust how strict country search is (0 = fuzzy, 1 = exact)

Disable Search

Remove search functionality from country list

Phone number

Different Dropdown Position

Control where the country list appears

Phone number

Real-world Examples ​

See how to use the component in common scenarios.

🏢 Business Form

Perfect for customer registration

Full Name
Email
Business Phone

🌍 Global Support

Multi-language international form

Número de teléfono

📱 Mobile-first Design

Optimized for mobile apps

Phone number

Data Handling ​

Understanding what data the component provides.

Enter your phone number in international format (e.g. +33612345678)

Troubleshooting ​

Common issues and solutions:

⚠️ Auto-formatting Issues ​

For countries like Anguilla (AI) with multiple valid number lengths, disable auto-formatting:

vue
<MazInputPhoneNumber auto-format="disabled" country-code="AI" />

🌐 Country Detection Not Working ​

Make sure to enable the right detection method:

vue
<!-- Browser locale (default) -->
<MazInputPhoneNumber :use-browser-locale="true" />

<!-- IP-based detection (requires internet) -->
<MazInputPhoneNumber fetch-country />

<!-- Manual fallback -->
<MazInputPhoneNumber country-code="US" />

Types ​

Results object emitted by @data event:

ts
interface MazInputPhoneNumberData {
  isValid: boolean
  isPossible?: boolean
  countryCode?: CountryCode
  countryCallingCode?: CountryCallingCode
  nationalNumber?: NationalNumber
  type?: NumberType
  formatInternational?: string
  formatNational?: string
  uri?: string
  e164?: string
  rfc3966?: string
  possibleCountries?: CountryCode[]
  phoneNumber?: string
}

Tips ​

TIP

This component use MazInput, so it inherits all his props

Props ​

NameDescriptionTypeRequiredDefaultPossible values
model-valuev-model The current value of the input field in international format (e.g. +33612345678)string | nullNo--
country-codev-model:country-code The selected country code (e.g. "FR")CountryCode | nullNo--
idUnique identifier for the componentstringNo--
placeholderText displayed when the input is emptystringNo--
top-labelStatic label displayed above the input field. Unlike the floating label, this remains fixedstringNo--
labelLabel displayed above the inputstringNo--
preferred-countriesList of country codes to place first in the select listCountryCode[]No--
ignored-countriesList of country codes to be removed from the select listCountryCode[]No--
only-countriesList of country codes to only have the countries selected in the select listCountryCode[]No--
translationsLocale strings of the component The default values are the translations of the MazUiTranslations pluginPartial<{ countrySelect: { placeholder: string; error: string; searchPlaceholder: string; }; phoneInput: { placeholder: string; example: string; }; }>No{ countrySelect: { error: 'Choose country', placeholder: 'Country code', searchPlaceholder: 'Search the country', }, phoneInput: { placeholder: 'Phone number', example: 'Example: {example}', }, }-
list-positionPosition where the list of countries will be openedMazPopoverPositionNo"bottom-start"'top' | 'left' | 'right' | 'bottom'
colorComponent color applied"primary" | "secondary" | "accent" | "info" | "success" | "warning" | "destructive" | "contrast" | "transparent"No"primary"'primary' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'destructive' | 'contrast' | 'transparent'
sizeComponent size applied"xs" | "sm" | "md" | "lg" | "xl" | "mini"No"md"'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'mini'
hide-flagsRemove flags in country listbooleanNofalse-
flag-srcSource of the flags, instead of the flagcdn.com CDN: a URL template (/flags/{code}.svg, {CODE} for uppercase) or a function giving the image source of a code. Use loadCountryFlag from maz-ui/country-flags for the flags of @maz-ui/icons. Can be set for the whole app with the defaults.global.flagSrc option of the MazUi plugin.MazCountryFlagSrcNoundefined (flags from flagcdn.com)-
disabledMake the input disabledbooleanNofalse-
requiredMake the input requiredbooleanNofalse-
exampleShow the phone number examplebooleanNotrue-
searchDisable search input in country listbooleanNotrue-
search-thresholdThreshold of the search input in country list where 1 is a perfect match and 0 is a match with any characternumberNo0.75-
use-browser-localeIf true, the browser locale will be usedbooleanNotrue-
fetch-countryThe component will make a request (https://ipwho.is) to get the location of the user and use it to set the default country codebooleanNofalse-
hide-country-selectHide the country selectorbooleanNofalse-
show-code-in-listShow country calling code in the country listbooleanNofalse-
custom-countries-listReplace country namesRecord<CountryCode, string>No--
auto-formatDisabled auto-format when phone is validfalse | "disabled" | "blur" | "typing"No"blur"'disabled' | 'blur' | 'typing'
country-localeLocale of country liststringNo--
validation-errorDisable validation error UIbooleanNotrue-
validation-successDisable validation success UIbooleanNotrue-
successAdd success UIbooleanNofalse-
errorAdd error UIbooleanNofalse-
warningAdd warning UIbooleanNofalse-
display-country-nameWill replace the calling code by the country name in the country selectorbooleanNofalse-
blockThe input will be displayed in full widthbooleanNofalse-
orientationOrientation of the inputs in the component"row" | "col" | "responsive"No"responsive"'row' | 'col' | 'responsive'
country-select-attributesMeta attributes of the country inputRecord<string, unknown>No{ name: "country", autocomplete: "off", style: { width: "14rem", }, }-
phone-input-attributesMeta attributes of the phone number input(Record<string, unknown> & { name: string; inputmode: "none" | "text" | "search" | "url" | "email" | "tel" | "numeric" | "decimal" | undefined; autocomplete: string; })No{ name: "phone", autocomplete: "tel", inputmode: "tel", }-
assistive-textHelper text displayed below the input to provide additional context or validation feedbackstringNo--
hintAlternative text that replaces the label when provided. Useful for contextual hintsstringNo--

Events ​

Event namePayloadDescription
update:model-valuevalue: string | null | undefinedEmitted when country or phone number changes
dataresults: MazInputPhoneNumberDataEmitted when country or phone number changes
country-codecountryCode?: CountryCode | null | undefinedEmitted when selected country changes
update:country-codecountryCode?: CountryCode | null | undefinedEmitted when country changes

Slots ​

NameDescriptionBindings
no-resultsReplace the "no results" icon in the country selector list-
selector-flagCountry selector flagcountryCode CountryCode - current selected country code Ex: "FR"
country-list-flagCountry list flagcountryCode CountryCode - country code of option Ex: "FR"
option CountryOption - country data
isSelected boolean - true if option is selected