Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6915495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:28:56+00:00 2026-05-27T09:28:56+00:00

Im trying to figure out how to mask text in a text input as

  • 0

Im trying to figure out how to mask text in a text input as though its a password field, only its not.
This is for a personal experiment and I unserdtand it may sound strange but its something I’d like to try, Ive used the replace method to change characters to asterisks only when I alert the value, it alerts * when the asterisk should only be a mask and the alert should show the true value, does this make sense and if so has anybody an idea of how to do this?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:28:56+00:00Added an answer on May 27, 2026 at 9:28 am

    The “obvious” solution (besides using a password field in the first place) is to have two fields, the display field with the mask and a hidden field with the real value:

    <input type="text" id="maskField1">
    <input type="hidden" id="hiddenField1" name="field1">
    
    <script>
    $("#maskField1").keyup(function(e) {
        var newText = this.value.replace(/\*/g,"");
        $("#hiddenField1")[0].value += newText;
        this.value = this.value.replace(/[^*]/g,"*");
    });
    </script>
    

    Unfortunately, as you can see with this demo: http://jsfiddle.net/PrHuE/ it only works as long as you add more characters to the end of the current text. A real solution is much more complicated than this because you have to allow for the user adding text in the middle of the string, or selecting multiple characters and then overtyping or explictly deleting, or pasting from clipboard, etc. I’m trapping keyup above, but user could paste with the mouse, so…

    Also if the user actually types some asterisks that confuses the above code.

    You can see I’m just taking any non-asterisk characters in the displayed mask field and appending them to the end of the hidden field before changing non-asterisks to asterisks. You could instead find the position within the string of those non asterisk characters and insert them to the same position in the hidden field. That wouldn’t be too hard. But figuring out which characters have been deleted (or replaced) would be much harder, way beyond what I have time for here.

    Solution 2: Create your own font where every character looks like an asterisk, then embed the font in your webpage and use it in the input field. For browsers that actually allow this it would be a no-code solution. For browsers that don’t allow it obviously it wouldn’t work at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to figure out this pseudo code. The following is assumed.... I can only
Trying to figure out the best way to do this: Should I do something
trying to figure out the best ActiveRecord inheritance strategy for this particular problem: I
Im trying to figure out how to mask all urls on my site to
Trying to figure out a way to throw out attributes in this data that
Trying to figure out how to clear my label's text...clear it out. So far
Trying to figure out what I'm doing wrong when trying to put $(this) in
Trying to figure out the best way to accomplish this. I have inhereted a
trying to figure out how to rewrite this url clientside blog.com/post/how-to-get-the-ladies to point serverside
Trying to figure out how to do this. I have the style but I'd

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.