
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Hide Email Address from Unauthorized Users in JavaScript
Hiding an e-mail address
The following steps are to be followed to hide our e-mail from unauthorized users.
- In every email address '@' symbol is common so try to remove it from the email address using split() method. In the following example after splitting the email(batman@gmail.com) we get the result as batman, gmail.com.
- Divide the result in to 2 parts(split1 and split2).
- Using substring() method remove some of string from split1 and join resulted part with split2 using '...@'.
- Return the joined part as the final output. In our example the resulted output is "bat...@gmail.com".
Example
<html> <body> <script type="text/javascript"> newEmail = function (email) { var split = email.split("@"); var split1 = split[0]; var avg = split1.length / 2; split1 = split1.substring(0, (split1.length - avg)); split2 = split[1]; return split1 + "...@" + split2; }; document.write(newEmail("batman@gmail.com")); </script> </body> </html>
output
bat...@gmail.com
Advertisements