Hide the Email Id in a form using HTML and JavaScript Last Updated : 30 Sep, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Hiding an email ID in a form using HTML and JavaScript involves obfuscating or masking the email address to enhance privacy or security. This can be achieved by partially hiding the email characters or storing the email in hidden fields until needed for processing.Examples:Input :[email protected] Output :robin*****@gmail.com Input :[email protected] Output :geeks*****@gmail.comApproach :Retrieve Email Input: The function test_str() retrieves the email entered by the user from the input field with id="t1".Identify @ Position: The function uses indexOf('@') to determine the position of the @ symbol within the email string.Mask Email: The characters before @ are partially replaced with asterisks using the replace() method and repeat() for masking.Display Result: The masked email is shown in the readonly field with id="t2", keeping the protected part hidden from view.Example: In this example we are following the above-explained approach. html <!DOCTYPE html> <html> <head> <title>Hide the Email Id in a form using HTML and JavaScript</title> <script type="text/javascript"> function test_str() { let str = document.getElementById("t1").value; let idx = str.indexOf('@'); let 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> Output:Hide the Email Id in a form using HTML and JavaScript Example Output Comment More infoAdvertise with us Next Article Hide the Email Id in a form using HTML and JavaScript A AnmolAgarwal Follow Improve Article Tags : Web Technologies HTML HTML-Misc Similar Reads How to create a Popup Form using HTML CSS and JavaScript ? To create a popup form using JavaScript, you can design a hidden overlay that becomes visible when triggered. We will use HTML for form elements, CSS for styling, and JavaScript to toggle the visibility of the overlay. This allows for a user-friendly and interactive way to display forms on your webp 3 min read How to Insert Email Address into Form using HTML5 ? In this article, we will learn how to add and get an email address of a user as data of the form by adding an email input field. As we know that an email_id is a vital component of user data. Email address is used for the verification of the user. It is also used to make contact with the submitters 2 min read How to create a hidden input field in form using HTML ? In this article, we will learn how to add a hidden input field into our form using HTML. A hidden control stores the data that is not visible to the user. It is used to send some information to the server which is not edited by the user. Normally, this hidden field usually contains the value which i 2 min read Create a Contact Form using HTML CSS & JavaScript A contact form is a web form used to collect user information and messages, facilitating communication between visitors and site owners. It is essential for feedback, inquiries, and support. Create a contact form using HTML for structure, CSS for styling, and JavaScript for validation and submission 3 min read How to remove âdisabledâ attribute from HTML input element using JavaScript ? In HTML, we use input elements for user input. The 'disabled' property helps prevent interaction with these elements. For example, if we only want users over 18 to input their Adhar card numbers, we can use JavaScript to remove the 'disabled' attribute when the user enters an age greater than 18. Th 2 min read Like