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

✨ 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.

Preferred Countries

Show your most common countries first

Only Specific Countries

Limit to certain countries only

Ignore Countries

Remove unwanted countries

Layout Orientations

Choose how the country selector and phone input are arranged.

Responsive (Default)

Stacks on mobile, side-by-side on desktop

Phone number

Always Row

Side-by-side on all screen sizes

Phone number

Always Column

Stacked on all screen sizes

Phone number

Display Options

Customize what information is shown to users.

Show Country Names

Display country names instead of calling codes

Phone number

Show Calling Codes in List

Help users see the dialing codes

Phone number

Hide Phone Examples

Remove the example phone number hints (visible when the phone input is focused)

Phone number

Hide Country Flags

Text-only country selection

Phone number

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 a phone number to see data

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
}

Props

NameDescriptionTypeRequiredDefaultPossible values
styleStyle attribut of the component root elementHTMLAttributes['style']Noundefined-
classClass attribut of the component root elementHTMLAttributes['class']Noundefined-
model-valuev-model
The current value of the input field in international format (e.g. +33612345678)
Example: "+33612345678"
string | undefined | nullNoundefined-
country-codev-model:country-code
The selected country code (e.g. "FR")
Example: "FR"
CountryCode | undefined | nullNoundefined-
idUnique identifier for the component
Example: "phone-input-1"
stringNoundefined-
placeholderText displayed when the input is empty
Example: "Enter your phone number"
stringNoundefined-
labelLabel displayed above the input
Example: "Phone Number"
stringNoundefined-
preferred-countriesList of country codes to place first in the select list
Example: ["FR", "BE", "GE"]
CountryCode[]Noundefined-
ignored-countriesList of country codes to be removed from the select list
Example: ["FR", "BE", "GE"]
CountryCode[]Noundefined-
only-countriesList of country codes to only have the countries selected in the select list
Example: ["FR", "BE", "GE"]
CountryCode[]Noundefined-
translationsLocale strings of the component The default values are the translations of the MazUiTranslations pluginPartial<MazUiTranslationsNestedSchema['inputPhoneNumber']>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 openedMazPopoverProps['position']No'bottom-start'top left, top right, bottom left, bottom right
colorComponent color appliedMazColorNo'primary'primary, secondary, accent, info, success, warning, destructive, contrast
sizeComponent size appliedMazSizeNo'md'xs, sm, md, lg, xl, mini
hide-flagsRemove flags in country listbooleanNofalse-
disabledDisable inputbooleanNofalse-
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>Noundefined-
auto-formatDisabled auto-format when phone is valid"blur" | "typing" | "disabled" | falseNo'blur'-
country-localeLocale of country list
Example: "fr-FR"
stringNoundefined-
validation-errorDisable validation error UIbooleanNotrue-
validation-successDisable validation success UIbooleanNotrue-
successAdd success UIbooleanNofalse-
errorAdd error 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 inputRecord<string, unknown>No() => ({ name: 'phone', autocomplete: 'tel', inputmode: 'tel', })-

Events

Event namePropertiesDescription
update:model-valuephoneNumber string - phoneNumber formattedEmitted when country or phone number changes
country-codecountryCode CountryCode - Country codeEmitted when selected country changes
update:country-codecountryCode CountryCode - Country codeEmitted when country changes
dataresults Results - metadata of current phone numberEmitted when country or phone number changes

Slots

NameDescriptionBindings
no-resultsReplace the "no results" icon in the country selector list
selector-flagCountry selector flagcountry-code String - current selected country code Ex: "FR"
country-list-flagCountry list flagcountry-code String - country code of option Ex: "FR"
option { iso2: string; dialCode: string; name: string; } - country data
is-selected Boolean - true if option is selected