Is it possible to control v-mask in Vue?

One challenge I am facing is with an input tag that utilizes v-mask for formatting a mobile number:

<input type="text" placeholder="Phone Number" id="phoneNumber" class="form-control"  
 v-model="numberAndCaptcha.phoneNumber" @keyup="onNumberChange" v-mask="mask"/>

mask:['###-###-####'] //defined as a data attribute

While this setup works well and the number gets formatted correctly as intended,

I have encountered an issue when trying to pre-populate the input with a number obtained from the backend upon reload.

The requirement is to mask the first six digits of the populated number, resulting in an input value like "******7890"

Unfortunately, due to restrictions within v-mask, the final input value only displays the last 4 digits of the pre-populated number since v-mask does not accept anything other than digits.

Is there a solution available to achieve the desired result on reload? Specifically, having a masked number that also complies with v-mask requirements?

Answer №1

The mask library utilizes various patterns, such as the # symbol that specifically accepts numerical values.

For more information, refer to: (from: https://github.com/vuejs-tips/vue-the-mask/blob/master/src/tokens.js)

export default {
  '#': { pattern: /\d/ },
  X: { pattern: /[0-9a-zA-Z]/ },
  S: { pattern: /[a-zA-Z]/ },
  A: { pattern: /[a-zA-Z]/, transform: v => v.toLocaleUpperCase() },
  a: { pattern: /[a-zA-Z]/, transform: v => v.toLocaleLowerCase() },
  '!': { escape: true }
}

This code snippet showcases the different patterns available. Here's a breakdown:

#: Accepts numbers only
X: Accepts numbers and upper/lowercase letters
S: Accepts letters as they are entered
A: Accepts letters and converts them to uppercase
a: Accepts letters and converts them to lowercase

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How does SWR affect React state changes and component re-rendering?

I am currently utilizing SWR for data fetching as outlined in the documentation: function App () { const [pageIndex, setPageIndex] = useState(0); // The API URL incorporates the page index, which is a React state. const { data } = useSWR(`/api/data? ...

Display Vue components in VuePress

Is there a way to showcase personalized Vue.js elements like a <b-button> on a VuePress markdown page? Can this be achieved? ...

POST request using Axios fails to authenticate with JWT token, yet the GET request is successfully authenticated

I'm currently working on setting up a REST API in Django to be connected with Vue.js on the front end. The connection is made using the axios library along with JWT token authentication. However, I've encountered an issue where Django responds w ...

What steps can be taken to prevent the controller action if the password and confirm password do not match?

Currently utilizing .Netcore MVC for my project. I am developing a registration page where users are required to input their email, password, and confirm the password. Although I can verify if the entered password matches the confirmation password, the con ...

Customize your DataGrid filtering with Material UI custom list filter feature

Exploring custom filters in the Material UI DataGrid has been an interesting experience for me. I found some useful information on https://material-ui.com/components/data-grid/filtering/ However, I encountered a challenge when trying to create a list with ...

The object's value might be undefined, despite having null checks in place

Currently using Typescript 4.0.5 and encountering a persistent Object is possibly undefined error message My local state includes a .csv file uploaded by the user const [currentLine, setCurrentLine] = useState<File>(); The useEffect function monit ...

Issue encountered in Angularjs during upgrade process from version 1.2.27 to 1.4.7

Recently, I upgraded my app from using AngularJS 1.2.27 to version 1.4.7, but now I am encountering an error in the AngularJS file. SyntaxError: Unexpected token : (angular.js:12477) at Function (native) at Object.sd. ...

Ways to expose an object in a Node module

One of my modules relies on a parsing functionality, with other modules needing to query the values provided by this parser. I have some key questions regarding its design: How should I approach building it in terms of design aspects? Which method should ...

Creating an asynchronous function in a Vue.js component that utilizes the Lodash library

I'm struggling with writing an async function correctly. Can someone provide guidance on how to achieve this? async search (loading, search, vm) { let vm = this _.debounce(() => { let ApiURL = '/users/' } let { res } = await ...

The duration for which an API Access Token remains valid is extremely brief

I recently started working with APIs and my current project involves using the Petfinder API v2 to develop a website that allows users to search for adoptable animals. The API utilizes OAuth, requiring a key and secret to obtain a token via CURL. However, ...

Yet another error encountered: "Headers cannot be set after they have already been sent to the client" when submitting the form

Whenever I try to submit text to a single-field form on my node.js server, I encounter the following error: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client at ServerResponse.setHeader (_http_outgoing.js:485:11) ...

Issue with Angular ngModel not syncing with variable changes

Currently using Angular 4 and Typescript, I have a table containing <select> elements in my template: <tr *ngFor="let task of tasksDetails"> <td>{{task.name}}</td> <td> <select class="form-control" [(ngMode ...

The useRouter() function doesn't seem to be successfully navigating to the main landing page

"use client" import { useState } from 'react'; import {auth} from '../../firebase-config' import {createUserWithEmailAndPassword} from 'firebase/auth' import { useRouter } from 'next/router'; const SignUp = ...

Retrieve the highest value indexes from a three-dimensional array with JavaScript

In my dataset, I have an array structured like this: [34, 12, 56] [100,125,19] [30,50,69] The highest value in this array is 125, so the index [1,1] is returned. This means that 125, the highest value, can be found in row 1, column 1. To determine the i ...

Navigate to the middle of a DIV container in Angular 7

Is there a way to programmatically scroll to the center of my element on both the Y and X axes when a specific function is executed? My HTML structure includes the following (I am aiming to scroll to the middle of #viewport): </div> <div # ...

Inserting Random Data into MySQL Tables using Node.js

I am currently working on developing a game bot for Discord similar to Town of Salem, Wolvesville, Feign, and others. Within my database, I have a table called "joinedplayer" which stores users who have used the "join" command: gamerid discordid 1 ...

Executing a function in cesium.js upon the occurrence of an event

I've set up a div like this: <div id="cesiumContainer" class="fullSize"></div> <div id="loadingOverlay"><h1>Loading...</h1></div> <div id="toolbar"><input type="search" id="search" placeholder="Search by l ...

Optimizing my AngularJS bundle is pushing me towards upgrading to Angular 5

Regarding my AngularJS application, it was initially created using 'yo angular-fullstack' with JS scripting instead of TS. It is functional but experiencing performance and user experience issues. The deployment is on AWS ElasticBeanstalk nano i ...

Using jQuery to make multiple requests with AJAX

I've encountered an issue with jQuery (ajax) and I need help with the following function: page: function(p, cont) { cont = typeof cont !== 'undefined' ? cont : this; $.ajax({ url: p, timeout: 10000, complet ...

The code begins executing even before the function has finished its execution

I believe that is what's happening, but I'm not entirely sure. There's code in a .js file that invokes a function from another .js file. This function performs an ajax call to a php page which generates and returns a list of radio buttons wi ...