Skip to content

Instantly share code, notes, and snippets.

@yuhisern7
Forked from gabrielfroes/emailmask.js
Created October 14, 2019 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuhisern7/23b9f3beac0f0f63c3e7141e81207787 to your computer and use it in GitHub Desktop.
Save yuhisern7/23b9f3beac0f0f63c3e7141e81207787 to your computer and use it in GitHub Desktop.
Javascript Email Mask
/*
Create a Mask in an email address
This function create a mask using a valid email address.
This is usefull when someone need to confirm the email used in a system
Author: Gabriel Froes - https://gist.github.com/gabrielfroes
*/
function emailMask(email) {
var maskedEmail = email.replace(/([^@\.])/g, "*").split('');
var previous = "";
for(i=0;i<maskedEmail.length;i++){
if (i<=1 || previous == "." || previous == "@"){
maskedEmail[i] = email[i];
}
previous = email[i];
}
return maskedEmail.join('');
}
// Usage:
// console.log ( emailMask("my.email@mydomain.com") );
// Output: my.e****@m*******.c**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment