Last active
July 4, 2018 23:19
-
-
Save rbenvenuto/99d738021d88b36be6be06de7046d8c6 to your computer and use it in GitHub Desktop.
JS function that replaces in-between characters with stars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hiddenEmailAddress(email) { | |
var emailLength = email.length; | |
var atPosition = email.search('@'); | |
var unhiddenPortion = email.slice(atPosition, emailLength); | |
var i; | |
var hiddenEmail = ''; | |
for(i = 0; i < atPosition; i++) { | |
if(i === 0 || i === atPosition - 1) { | |
hiddenEmail += email[i]; | |
} else { | |
hiddenEmail += email[i].replace(email[i], '*'); | |
} | |
} | |
hiddenEmail += unhiddenPortion; | |
return hiddenEmail; | |
} | |
hiddenEmailAddress('[email protected]'); | |
// a*******[email protected]' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment