Hide the Email Id in a form using HTML and JavaScript

Here the following task is going to be formed with HTML code:
1.Input field: We are going to enter the email id in this field.
2.Button: On clicking this button hidden email id will be displayed.
3.Output field: Field to display hidden email id.

Examples:

Input :robin_singh@gmail.com 
Output :robin*****@gmail.com

Input :geeksforgeeks@gmail.com
Output :geeks*****@gmail.com

HTML code :

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
    <html>
      <head>
         <title></title>
         <script type="text/javascript">
            function test_str(){
               var str = document.getElementById("t1").value ;
               var idx = str.indexOf('@');
               var res = str.replace(str.slice(5, idx), "*".repeat(5));
               document.getElementById("t2").value = res;
             }
         </script>
       </head>
       <body>
         <p>
             Email: <input type="text" placeholder="abc" id="t1"/><br/>
             <input type="button" value="Protect" onclick="test_str()"/><br/>
             Output: <input type="text" id="t2" readonly/>
         </p>
      </body>
  </html>

chevron_right


Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.

About immukul

Executive Software Developer at Cavisson Systems