Skip to content

Docs for v3 and v4.x.x

Installation

npm

bash
  npm install vue-tel-input

Install the plugin into Vue:

javascript
import Vue from 'vue'
import VueTelInput from 'vue-tel-input'

Vue.use(VueTelInput, [globalOptions = {}]) // Define default global options here (optional)

View all available options in Props.

Or use the component directly:

html
<!-- your-component.vue-->
<template>
  <vue-tel-input v-model="value"></vue-tel-input>
</template>
<script>
import { VueTelInput } from 'vue-tel-input'

export default {
  components: {
    VueTelInput,
  },
};
</script>

Browser

Include vue-tel-input in the page.

html
<script src="https://unpkg.com/vue-tel-input@4.4.2"></script>

If Vue is detected in the Page, the plugin is installed automatically.

Manually install the plugin into Vue:

javascript
Vue.use(VueTelInput)

Or use the component directly:

javascript
Vue.component('vue-tel-input', VueTelInput.VueTelInput)

Use as a custom field of vue-form-generator

Check out the setup in CodeSandbox.

  • Add a component using vue-form-generator's abstractField mixin

    html
      <!-- tel-input.vue -->
      <template>
        <vue-tel-input v-model="value"></vue-tel-input>
      </template>
    
      <script>
      import { abstractField } from 'vue-form-generator';
    
      export default {
        name: 'TelephoneInput',
        mixins: [abstractField],
      };
      </script>
  • Register the new field as a global component

    js
      import Vue from 'vue';
      import TelInput from '<path>/tel-input.vue';
    
      Vue.component('field-tel-input', TelInput);
  • Now it can be used as tel-input in schema of vue-form-generator

    js
    var schema: {
      fields: [{
          type: "tel-input",
          label: "Awesome (tel input)",
          model: "telephone"
      }]
    };

Read more on vue-form-generator's instruction page

Usage

Props

Test all props on CodeSandbox.

PropertyTypeDefault valueDescription
autocompleteString'on'Native input 'autocomplete' attribute
autofocusBooleanfalseNative input 'autofocus' attribute
defaultCountryString | Number''Default country (by iso2 or dialCode), will override the country fetched from IP address of user
disabledBooleanfalseDisable input field
disabledFetchingCountryBooleanfalseDisable fetching current country based on IP address of user
dropdownOptionsObject{ disabledDialCode: false, tabindex: 0 }Options for dropdown, supporting disabledDialCode and tabindex
dynamicPlaceholderBooleanfalsePlaceholder as a sample phone number in the current country, available from v3.1.1
enabledCountryCodeBooleanfalseEnable country code in the input
enabledFlagsBooleantrueEnable flags in the input
ignoredCountriesArray[]List of countries will NOT be shown on the dropdown. ie ['AU', 'BR']
inputClassesString | Array | Object''Custom classes for the input
inputIdString''Custom 'id' for the input
inputOptionsObject{ showDialCode: false, tabindex: 0 }Options for input, supporting showDialCode (always show dial code in the input) and tabindex
maxLenNumber25Native input 'maxlength' attribute
modeString''Format number to 'international' (with + dial code) or 'national' (with 0...), available from v3.1.1
nameString'telephone'Native input 'name' attribute
onlyCountriesArray[]List of countries will be shown on the dropdown. ie ['AU', 'BR']
placeholderString'Enter a phone number'Placeholder for the input
preferredCountriesArray[]Preferred countries list, will be on top of the dropdown. ie ['AU', 'BR']
requiredBooleanfalseRequired property for HTML5 required attribute
validCharactersOnlyBooleanfalseOnly allow valid characters in a phone number (will also verify in mounted, so phone number with invalid characters will be shown as an empty string)
wrapperClassesString | Array | Object''Custom classes for the wrapper
customValidateBoolean | RegExpfalseCustom validation RegExp for input, available from v4.1.0

Events

EventArgumentsDescriptionNotes
inputString, ObjectFires when the input changes with the argument is the object includes { number, isValid, country }onInput deprecated
validateObjectFires when the correctness of the phone number changes (from true to false or vice-versa) and when the component is mounted { number, isValid, country }onValidate deprecated
blurFocusEventFires on blur eventonBlur deprecated
focusFocusEventFires on focus event
spaceKeyboardEventFires on keyup.space eventonSpace deprecated
enterKeyboardEventFires on keyup.enter eventonEnter deprecated
openFires when the flags dropdown opens
closeFires when the flags dropdown closes
country-changedObjectFires when country changed (even for the first time)Available from v2.4.2

Slots

SlotDescriptionNotes
arrow-iconReplace the arrow next to the flag with a component of your choiceAvailable from v2.4.3

Credits

Credits

made with ❤ by Steven.