Simple input field to format international phone numbers inspired by VuePhoneNumberInput. Made with VueJS π
β v-mask π
Feel free to play with it
yarn add simple-phone-number-input
npm i --save simple-phone-number-input
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 | Type | Required | Default |
|---|---|---|---|
| v-model | String | true | - |
| locale | String | false | 'es' |
| default-country-code | String | false | 'sv' |
| input-class * | String | false | - |
| selector-class * | String | false | - |
| no-dial-code | Boolean | false | false |
| no-country-selector | Boolean | false | false |
* These properties are used to apply custom or framework css classes.
| Event | Return |
|---|---|
| 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
}
| Property | Type | Description |
|---|---|---|
| phoneNumberExample | String | Local phone number example of the selected country |
| countryCode | String | Selected country code ISO 3166-1 alpha-2 |
| countryCallingCode | String | Selected country calling code |
| nationalNumber | String | Formatted national phone number |
| internationalNumber | String | Formatted international phone number |
| isValid | Boolean | Validation result of the current phone number. Check libphonenumber-js for more info: isValid() |
| Slot | Action |
|---|---|
| label | Override the current label for the phone number input. Supported languages: spanish and english. |
If you have any suggestions, problems or ideas feel free to add a new issue
npm installnpm run servenpm run lintThis project is licensed under MIT License