Currently, I am in the process of developing a Vue application that will display * characters instead of revealing the actual input entered by the user (similar to a password field). While I have successfully implemented this functionality, I am encountering an issue with retrieving the exact value entered by the user. For example, if the user enters 123-45-6789, I should be able to access that precise value while displaying it as *** - ** - **** within the input box.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vue</title>
</head>
<body>
<div id="app">
<div>
Input:
<input
type="text"
class="form-control"
name="sector"
id="sector"
:value="maskedDataComp"
required
@input="onInput"
/>
{{ someDataComp }}
</div>
</div>
<script src="https://unpkg.com/vue"></script>
<script src="https://cdn.jsdelivr.net/npm/v-mask/dist/v-mask.min.js"></script>
<script>
const app = new Vue({
el: "#app",
data() {
return {
someData: "",
maskedData: "",
};
},
computed: {
someDataComp: {
get() {
return this.someData;
},
set(val) {
this.someData = val;
},
},
maskedDataComp() {
this.maskedData = this.someDataComp.replace(/\d/g, "*");
console.log(this.maskedData);
return this.maskedData;
},
},
methods: {
onInput(element) {
this.someDataComp = element.target.value;
},
},
});
</script>
</body>
</html>
In essence, my goal is to visually represent the input as ***- **- **** when the user types 123456789 without resorting to using a password field. Kindly refrain from suggesting or providing a solution involving password implementation.