InputMask

InputMask component is used to enter input in a certain format such as numeric, date, currency, email and phone.


npx volt-vue add InputMask


import InputMask from '@/volt/InputMask.vue';

InputMask is used with the v-model property for two-way value binding.


<template>
    <div class="card flex justify-center">
        <InputMask v-model="value" mask="99-999999" placeholder="99-999999" />
    </div>
</template>

<script setup lang="ts">
import InputMask from '@/volt/InputMask.vue';
import { ref } from 'vue';

const value = ref(null);
</script>

Mask format can be a combination of the following definitions; a for alphabetic characters, 9 for numeric characters and * for alphanumberic characters. In addition, formatting characters like (, ) , - are also accepted.


<template>
    <div class="card flex flex-wrap gap-4">
        <div class="flex-auto">
            <label for="ssn" class="font-bold block mb-2">SSN</label>
            <InputMask id="ssn" v-model="value1" mask="999-99-9999" placeholder="999-99-9999" fluid />
        </div>

        <div class="flex-auto">
            <label for="phone" class="font-bold block mb-2">Phone</label>
            <InputMask id="phone" v-model="value2" mask="(999) 999-9999" placeholder="(999) 999-9999" fluid />
        </div>

        <div class="flex-auto">
            <label for="serial" class="font-bold block mb-2">Serial</label>
            <InputMask id="serial" v-model="value3" mask="a*-999-a999" placeholder="a*-999-a999" fluid />
        </div>
    </div>
</template>

<script setup lang="ts">
import InputMask from '@/volt/InputMask.vue';
import { ref } from 'vue';

const value1 = ref(null);
const value2 = ref(null);
const value3 = ref(null);
</script>

When the input does not complete the mask definition, it is cleared by default. Use autoClear property to control this behavior. In addition, ? is used to mark anything after the question mark optional.


<template>
    <div class="card flex justify-center">
        <InputMask v-model="value" mask="(999) 999-9999? x99999" placeholder="(999) 999-9999? x99999" />
    </div>
</template>

<script setup lang="ts">
import InputMask from '@/volt/InputMask.vue';
import { ref } from 'vue';

const value = ref(null);
</script>

Default placeholder for a mask is underscore that can be customized using slotChar property.


<template>
    <div class="card flex justify-center">
        <InputMask v-model="value" placeholder="mm/dd/yyyy" mask="99/99/9999" slotChar="mm/dd/yyyy" />
    </div>
</template>

<script setup lang="ts">
import InputMask from '@/volt/InputMask.vue';
import { ref } from 'vue';

const value = ref(null);
</script>

Specify the variant property as filled to display the component with a higher visual emphasis than the default outlined style.


<template>
    <div class="card flex justify-center">
        <InputMask v-model="value" variant="filled" mask="99-999999" placeholder="99-999999" />
    </div>
</template>

<script setup lang="ts">
import InputMask from '@/volt/InputMask.vue';
import { ref } from 'vue';

const value = ref(null);
</script>

InputMask provides small and large sizes as alternatives to the base.


<template>
    <div class="card flex flex-col items-center gap-4">
        <InputMask v-model="value1" placeholder="Small" size="small" mask="99-999999" />
        <InputMask v-model="value2" placeholder="Normal" mask="99-999999" />
        <InputMask v-model="value3" placeholder="Large" size="large" mask="99-999999" />
    </div>
</template>

<script setup lang="ts">
import InputMask from '@/volt/InputMask.vue';
import { ref } from 'vue';

const value1 = ref(null);
const value2 = ref(null);
const value3 = ref(null);
</script>

Invalid state is displayed using the invalid prop to indicate a failed validation. You can use this style when integrating with form validation libraries.


<template>
    <div class="card flex flex-wrap justify-center gap-4">
        <InputMask v-model="value" mask="99-999999" placeholder="Serial Key" :invalid="!value" />
    </div>
</template>

<script setup lang="ts">
import InputMask from '@/volt/InputMask.vue';
import { ref } from 'vue';

const value = ref(null);
</script>

When disabled is present, the element cannot be edited and focused.


<template>
    <div class="card flex justify-center">
        <InputMask v-model="value" mask="99-999999" placeholder="Disabled" disabled />
    </div>
</template>

<script setup lang="ts">
import InputMask from '@/volt/InputMask.vue';
import { ref } from 'vue';

const value = ref(null);
</script>