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>
  <mc-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>
  <mc-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>
  <mc-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>
  </mc-input-contact-number>
</template>

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

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

Disabled State

vue
<template>
  <mc-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>
  <mc-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>
  <mc-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"
    @get-parsed-international-number="handleParsedNumber"
  />
</template>

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

const inputModel = ref('');
const selectedCountry = ref('');
const selectedCalling = ref('');
const errors = ref([]);
const parsedNumber = 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;
};

const handleParsedNumber = (val: string) => {
  parsedNumber.value = val;
};
</script>

Pre-Selected Country

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

Display Helper

Display helpful text or error messages below the input field using the display-helper, helper-text, helper-icon, and error props. You can also customize the helper message with a slot.

Helper Text

Enter a valid international phone number

Error State with Helper

Invalid phone number format

Custom Helper Message

Enter number with country code prefix
0 characters
vue
<template>
  <div class="mc-grid mc-gap-4">
    <!-- Helper Text -->
    <mc-input-contact-number
      id="input-contact-number-helper-text"
      v-model="inputModel"
      label="Input Contact Number"
      display-helper
      helper-text="Enter a valid international phone number"
    />

    <!-- Error State with Helper -->
    <mc-input-contact-number
      id="input-contact-number-error-helper"
      v-model="inputModel"
      label="Input Contact Number"
      display-helper
      helper-icon="ph:warning-circle-fill"
      helper-text="Invalid phone number format"
      error
    />

    <!-- Custom Helper Message -->
    <mc-input-contact-number
      id="input-contact-number-custom-helper"
      v-model="inputModel"
      label="Input Contact Number"
      display-helper
      helper-icon="ph:info-fill"
      helper-text="Phone number info"
    >
      <template #helperMessage>
        <div class="mc-flex mc-w-full mc-justify-between mc-gap-2">
          <div class="mc-body-sm-regular mc-flex mc-items-center mc-gap-1">
            <Icon class="mc-min-h-5 mc-min-w-5" icon="ph:info-fill" />
            <span>Enter number with country code prefix</span>
          </div>
          <div class="mc-body-sm-regular">{{ inputModel.length }} characters</div>
        </div>
      </template>
    </mc-input-contact-number>
  </div>
</template>

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

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

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
display-helperWhen set to true, displays the helper text below the input field.Booleanfalse
helper-textHelper text to display below the input when display-helper is true. Provides additional context or instructions for the user.String''
helper-iconIcon name to display alongside the helper text. Accepts any icon name from the icon library.Stringnull
errorWhen set to true, displays the input in an error state with red text for the helper message.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.