What is the method for retrieving the input value once it has been obscured with asterisks (*)?

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.

Answer №1

I decided to implement this addition after reviewing @dave's Answer.

<!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">
      <input type="text" @input="onInput" v-model="someData" />
    </div>
    <script src="https://unpkg.com/vue"></script>
    <script src="https://cdn.jsdelivr.net/npm/v-mask/dist/v-mask.min.js"></script>
    <script>
      Vue.filter("uppercase", function (value) {
        return value.replace(/\d/g, "*");
      });
      const app = new Vue({
        el: "#app",
        data() {
          return {
            someData: "",
            maskedData: "",
          };
        },
        computed: {
          getMaskedData() {
            return this.maskedData;
        },
        },
        methods: {
          onInput(e) {
            let maskString = e.data
            if(!!maskString)
            this.maskedData += maskString;
            console.log('mask', this.getMaskedData)
            this.someData = this.$options.filters.uppercase(e.target.value);
          },
        },
      });
    </script>
  </body>
</html>

Answer №2

A straightforward approach involves utilizing basic HTML.

<input type="password" id="pwd" name="pwd" minlength="8">

The use of the password type will conceal the characters while still allowing access.

update:

In situations where the input should consist of separate numbers (such as credit cards), individual input boxes are often used (in this case, they would be password type) and validated to switch to the next box once the maximum number is reached.

I hope this explanation proves helpful!

You can capture the entered value using @keyup, and store it in a variable before making any replacements.

<input id="field1" type="text" @keyup="keymonitor" v-model="ThisIsField1">

then utilize the keymonitor method to retrieve the value being inputted into the field.

keymonitor: function(event) {
        console.log(event.key);
    }

One drawback of this method is that individuals may enter numbers at different positions, making it challenging to track easily.

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

Prevent ng-click from functioning in AngularJS when a specific variable is met

<span class="column__list--total fa" ng-class="{'fa-check': skill.done == 1, 'fa-times red': skill.done == 0}" ng-click="skill.disabled || toggleSkill(skill.id, person.id)" ng-hide="$root.user[0].auth == 2"></span> <span ...

Having Ionic call the submit method within another method seems to be causing some issues

I have a submit method that posts data to the server when a submit button is clicked. It works fine when done manually, but I want to automate it so that it is triggered after input texts are filled without having to press the submit button every time. H ...

Injecting resolve values from UI router into Angular Jasmine tests

I am facing an issue in my Angular application where UI router resolves a promise into the controller. However, when attempting to test this controller using Karma, I receive an error about an unknown provider. How can I inject a mock object into the test ...

Ways to showcase multiple elements using introjs

I am attempting to highlight multiple DOM elements using the JS library intro.js, but I am encountering an issue. It seems that I can only define one element to be highlighted at a time. introjs.setOptions({ steps: [ { ...

Only the initial TinyMCE editor that was added dynamically is visible, the rest are not showing

I am currently developing a javascript application that will showcase a real-time discussion thread. The app will regularly communicate with the server to fetch new data and display it on the page. To enable users to post comments and replies, we have deci ...

In Next.js, encountering an error when using canvas drawImage

I am attempting to upload a local image onto a canvas element, but I keep encountering an error: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLCanvasElement ...

When I try to open my modal in Electron by clicking on the button, it doesn't work

I was expecting the modal to open by clicking on the Edit button within #app, but it doesn't open at all! I am unsure if there is an issue with my JavaScript logic or my HTML code! When attempting to use a function for the Modal, it still does not wo ...

Is it possible to generate a coordinate grid comprised of clickable div elements with HTML, CSS, and Javascript - with the option to utilize JQuery if necessary?

Here is a link to the code on JFiddle: http://jsfiddle.net/4v2n7wk9/1/ <html> <head> <title>Example of Grid Buttons</title> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui ...

Windowing box inside a container box

I am looking to implement scrolling for just the "chat-messages" div within the "chat-bar" div on my site. I want only this specific section to be scrollable, while the rest of the site remains stationary. Currently, I have to scroll through the entire pag ...

A guide to testing window.pageYoffset in webdriverIO using chai assertions

When conducting a selenium test using WebDriverIO and Chai, I encountered the need to capture the position of window.pageYoffset. Unfortunately, I was unable to find a direct way to do this in WebDriverIO. My initial attempts involved: browser.scroll(0, 2 ...

issue occurring after inserting a new parameter

I encountered an issue with my test case after adding a new parameter tiger to the method swimming. Despite passing the new parameter tiger to my test case, it continues to break. Update: I am receiving an "undefined grid" error at this line. Any suggest ...

Having trouble initiating npm?

I am currently learning Angular2, and I encountered some issues when trying to initiate the npm server by running npm start in the project's directory. Here are the errors I received: > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" ...

Scrolling through UL elements using Jquery

I am struggling to implement jQuery for scrolling a UL list, with two span elements for moving up and down. It works fine for a single li child, but how can it work for a dynamically filled ul? Any help would be greatly appreciated, as I am completely lo ...

Fetch the count of files in a directory using AJAX

I'm attempting to fetch the number of files in a folder and compare it with the maxfiles value. Within dropzone.js, there is a function that looks like this: Dropzone.prototype._updateMaxFilesReachedClass = function() { if ((this.options.maxF ...

Is there a method to indicate type narrowing to TypeScript following an initial null/undefined validation?

After loading environment variables into my Node & Express app using 'dotenv', I take steps to ensure these values are present and of the correct type before starting the server. However, when attempting to use these variables later on, TypeScrip ...

Error: Unable to execute function abc, it is not defined as a function in this context

Having trouble with a fronted or JavaScript issue where it can't find the defined function in the file. I'm working on integrating Apple Pay and need to call the back-end API based on a specific event. Here is my code. ACC.payDirect = { _autoload ...

Is the params object sorted by $http in AngularJS?

Currently, I am in the process of writing unit tests for my AngularJS application. In order to perform these tests, I am utilizing the $httpBackend to mock the $http request internally. During the testing phase, I make use of $httpBackend.expectGET to ens ...

Difficulties with angular ui-router authentication problems

When setting notify to true, the login.html does not render - it shows up as a blank page. However, if set to false, I receive multiple errors in the console: RangeError: Maximum call stack size exceeded at $.resolve (angular-ui-router.min.js:1) a ...

How to activate Yii2 confirmation popup

I have a special ActionColumn on my GridView and I'm attempting to use the yii.confirm function with the data-confirm attribute for the delete action, but the dialog box is not appearing. [ 'format'=>'html', 'content' ...

I am puzzled as to why my code in React is rendering twice without any apparent reason

I ran into a strange issue where my console.log("hi") was being displayed twice. I was working on a simple todo-list project and noticed that everything was getting double clicked. After some troubleshooting, it seems like the code is executing any JavaScr ...