I have a "forgot email" page in our MEAN app where I need to show an email clue/hint to the user if the details that the user provided is successfully verified.
Let's say the user have the following email: janedoe@example.com
.
The hint should be displayed in the following format: j*****e@example.com
.
I tried using split()
and replace()
and I'm able to produce a result in the following format: *******@example.com
.
The issue right now is that the first and last character before the @
symbol are also replaced which should not be the case.
I created a simple code to show my current solution below.
angular.module('app', []).controller('TestController', ['$scope', function($scope) {
var email = 'janedoe@example.com';
var emailParts = email.split('@');
$scope.emailClue = emailParts[0].replace(/./gi, '*') + '@' + emailParts[1];
console.log($scope.emailClue);
}])
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="TestController">
<p>Our records show your email address as {{ emailClue }}. Please use this email to log in.</p>
</div>
I would really appreciate any help. Thanks.