
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Masking email to hide it in JavaScript
It is a common practice that when websites display anyone's private email address they often mask it in order to maintain privacy.
Therefore for example −
If someone's email address is −
const email = 'ramkumar@example.com';
Then it is displayed like this −
const masked = 'r...r@example.com';
We are required to write a JavaScript function that takes in an email string and returns the masked email for that string.
Example
Following is the code −
const email = 'ramkumar@example.com'; const maskEmail = (email = '') => { const [name, domain] = email.split('@'); const { length: len } = name; const maskedName = name[0] + '...' + name[len - 1]; const maskedEmail = maskedName + '@' + domain; return maskedEmail; }; console.log(maskEmail(email));
Output
Following is the output on console −
r...r@example.com
- Related Articles
- Masking a string JavaScript
- How to validate email address in JavaScript?
- How to hide/show HTML elements in JavaScript?
- How to use JavaScript to hide a DIV when the user clicks outside of it?
- Need for masking in 8085
- How to hide HTML element with JavaScript?
- How to validate email address using RegExp in JavaScript?
- What is data masking?
- How to hide a div in JavaScript on button click?
- Validating email and password - JavaScript
- What is masking an image in OpenCV?
- How to hide e-mail address from an unauthorized user in JavaScript?
- Hide div that contains specific text with JavaScript?
- How to hide lines in Matplotlib?
- How to hide in IPython notebook?

Advertisements