1.3.0 • Published 9 months ago

v-phone-number v1.3.0

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
9 months ago

v-phone-number

Phone number form input visually compatible with Vuetify projects running on Vue 2.x. Allows users to enter in their phone number in their localized, native format while giving your app an E164 formatted string suitable for SMS and VoIP APIs.

Demo

Demo GIF

Requirements

Proven with the following minimum versions of Vue and Vuetify.

Installation

npm i -s v-phone-number

Add the component as normally to use in a single component or view

import VPhoneNumber from 'v-phone-number';
// ...
export default {
  components: {
    VPhoneNumber,
    // ..
  },
};

To add v-phone-number to the entire app, register the component in either plugins/vuetify.js or directly in main.js

import VPhoneNumber from 'v-phone-number';
// ...
Vue.component('v-phone-number', VPhoneNumber);

Usage

<v-phone-number label="Phone Number" v-model="phoneNumber" />

Props

Most v-text-field props but not:

  • counter
  • counter-value
  • hide-spin-buttons
  • rules (use landline, mobile, required and strict)
  • type (hard-coded to tel for optimal mobile experience)

The following props are enabled, but will make the input look bad unless you turn off the country selector or dig in with some unscoped CSS to support your use case (see "Advanced" below).

  • height
  • filled, label, placeholder, and persistent-placeholder simulataneously
  • prefix
  • reverse
  • solo-inverted
  • suffix

Additionally the following phone-specific properties are available.

NameTypeDefaultDescription
default-countrystring'US'ISO 3166 Country code to initialize the input with. If the input is created with a value, the country code of the E164 number given is always used.
disable-country-selectbooleanfalseHide the country selector entirely.
excluded-countriesarray[]ISO 3166 country codes to exclude as choices for locality. Ignored if value is an empty array. If the input is created with a value, the country code of the E164 number given is always used.
included-countriesarray[]The complete list of ISO 3166 country codes to inlude as choices for locality. Ignored if value is an empty array. If the input is created with a value, the country code of the E164 number given is always used.
hide-calling-codebooleanfalseHide the calling code prefix of the selected country.
hide-flagbooleanfalseHide the flag emoji of the selected country.
landlinebooleanfalseOnly accept fixed landline number.
languagestring'en'ISO 639 language code of the component's content. Languages with fewer than five million native speakers as of August 2023 may not be supported. National locales have no effect.
mobilebooleanfalseOnly accept mobile number.
show-country-codebooleanfalseDisplay the ISO 3166 country code of the selected country.
strictbooleanfalseIf false, validation only checks there are enough digits in the phone number for the selected country. If true, the value itself will be checked (ie, no US area code begins with a zero).
voipbooleanfalseOnly accept voice over IP number.

Events

All v-text-field events and:

NameTypeDescription
phone-numberPhoneNumberUnderlying PhoneNumber object, see libphonenumber-js for structure
update:country-codestringISO 3166 country code of the selected country from the menu

Slots

Most v-text-field slots but not:

  • counter
  • prepend-inner while disable-country-select is false
  • progress

Advanced

This project uses BEM (Block Element Modifier) class hierarchy for its components, allowing for precise control over the appearance of this input should the default Vuetify style defaults be found wanting. The block is v-phone-number, and contains the following elements:

  • country-code
  • country-code-display
  • country-code-search
  • country-list
  • number-input

There are no modifiers to these classes.

1.3.0

9 months ago

1.2.1

9 months ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago