1.0.1 • Published 4 years ago

simple-phone-number-input v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

simple-phone-number-input

vue 2 license

Simple input field to format international phone numbers inspired by VuePhoneNumberInput. Made with VueJS 💚

📦 Third party packages

v-mask 💚

libphonenumber-js

Installation

Using yarn

yarn add simple-phone-number-input

Using npm

npm i --save simple-phone-number-input

Usage

ES6 Modules / CommonJS

import SimplePhoneNumberInput from "simple-phone-number-input";
import "simple-phone-number-input/dist/simple-phone-number-input.css";

Vue.use(SimplePhoneNumberInput);
<simple-phone-number-input v-model="yourValue" />

Props API

PropsTypeRequiredDefault
v-modelStringtrue-
localeStringfalse'es'
default-country-codeStringfalse'sv'
input-class *Stringfalse-
selector-class *Stringfalse-
no-dial-codeBooleanfalsefalse
no-country-selectorBooleanfalsefalse

* These properties are used to apply custom or framework css classes.

Events API

EventReturn
onFormatted- emitted when new value is enter on phone number input and return an object of different formatted phone number values (1)

(1) - Example of object returned when onFormatted event is emitted:

{
  phoneNumberExample: "70123456",
  countryCode: "SV",
  countryCallingCode: "503",
  nationalNumber: "72665487",
  internationalNumber: "+50372665487",
  isValid: true
}

Object properties definition

PropertyTypeDescription
phoneNumberExampleStringLocal phone number example of the selected country
countryCodeStringSelected country code ISO 3166-1 alpha-2
countryCallingCodeStringSelected country calling code
nationalNumberStringFormatted national phone number
internationalNumberStringFormatted international phone number
isValidBooleanValidation result of the current phone number. Check libphonenumber-js for more info: isValid()

Named slots

SlotAction
labelOverride the current label for the phone number input. Supported languages: spanish and english.

✌ Contributing

If you have any suggestions, problems or ideas feel free to add a new issue

Project setup

npm install

Compiles and hot-reloads for development

npm run serve

Lints and fixes files

npm run lint

License

This project is licensed under MIT License