Skip to content

Contact Number Input

  • This component utilizes libphonenumber-js to parse and format the input on blur.
  • International contact number input with country selector and validation.

Uses libphonenumber-js internally for parsing and formatting on blur.

Basic Usage

vue
<template>
  <spr-input-contact-number id="input-contact-number-basic" v-model="inputModel" label="Input Contact Number" />
</template>

<script setup lang="ts">
import { ref } from 'vue';

const inputModel = ref('');
</script>

Active State

vue
<template>
  <spr-input-contact-number
    id="input-contact-number-active-state"
    v-model="inputModel"
    label="Input Contact Number"
    active
  />
</template>

<script setup lang="ts">
import { ref } from 'vue';

const inputModel = ref('');
</script>

Error State

vue
<template>
  <spr-input-contact-number
    id="input-contact-number-error-state"
    v-model="inputModel"
    label="Input Contact Number"
    error
  >
    <template #icon>
      <Icon icon="ph:warning-circle-fill" />
    </template>
  </spr-input-contact-number>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const inputModel = ref('');
</script>

Disabled State

vue
<template>
  <spr-input-contact-number
    id="input-contact-number-disabled-state"
    v-model="inputModel"
    label="Input Contact Number"
    disabled
  />
</template>

<script setup lang="ts">
import { ref } from 'vue';

const inputModel = ref('');
</script>

Disabled Country Calling Code

vue
<template>
  <spr-input-contact-number
    id="input-contact-number-disabled-country-calling-code"
    v-model="inputModel"
    label="Input Contact Number"
    :disabled-country-calling-code="true"
  />
</template>

<script setup lang="ts">
import { ref } from 'vue';

const inputModel = ref('');
</script>

Get Selected Country Codes

Model Output:

Selected Country Code:

Selected Country Calling Code:

Error Handling: []

Parsed International Number:

vue
<template>
  <spr-input-contact-number
    id="input-contact-number-selected-country-codes"
    v-model="inputModel"
    label="Input Contact Number"
    @get-selected-country-calling-code="handleCodes"
    @get-contact-number-errors="handleErrors"
  />
</template>

<script setup lang="ts">
import { ref } from 'vue';

const inputModel = ref('');
const selectedCountry = ref('');
const selectedCalling = ref('');
const errors = ref([]);

const handleCodes = (val: { countryCode: string; countryCallingCode: string }) => {
  selectedCountry.value = val.countryCode;
  selectedCalling.value = val.countryCallingCode;
};

const handleErrors = (val: { title: string; message: string }[]) => {
  errors.value = val;
};
</script>

Pre-Selected Country

vue
<template>
  <spr-input-contact-number
    id="input-contact-number-preselected-country"
    v-model="inputModel"
    label="Input Contact Number"
    pre-selected-country-code="US"
  />
</template>

API Reference

NameDescriptionTypeDefault
idThe unique id for the componentString''
v-modelThe current (unformatted) input value. Updates on user input and formatting events.String''
placeholderPlaceholder text displayed when the input is empty.String'Enter Phone Number'
pre-selected-country-codeInitial ISO 3166-1 alpha-2 country code used to derive the default calling code (e.g., PH, US).String'PH'
disabledDisables the entire contact number input (including country selector).Booleanfalse
disabled-country-calling-codeDisables only the country calling code selector while keeping the number field interactive.Booleanfalse

For additional shared props, events, slots, and behavior inherited from the base input component, please refer to the Input Component API Reference.

Events

EventPayloadDescription
@update:model-valueStringEmitted whenever the raw input value changes (two-way binding support).
@get-selected-country-calling-code{ countryCode: String; countryCallingCode: String }Emitted after country selection changes, providing both the ISO country code and its calling code.
@get-parsed-international-numberStringEmitted with the fully parsed international number (e.g., +15551234567) after formatting logic runs.
@get-contact-number-errorsArray<{ title: String; message: String }>Emitted with validation error objects if parsing or formatting detects issues.