简体   繁体   English

隐藏带星号的文本

[英]Hide text with asterisks

I am trying to hide a type of string data that the user types and then by means of a data bing in agular I show it in another component and what I want is to mask/hide part of this data with asterisks.我试图隐藏用户键入的一种字符串数据,然后通过 agular 中的数据 bing 在另一个组件中显示它,我想要的是用星号屏蔽/隐藏部分数据。 How can I do it?我该怎么做? I am not very expert in js, is it possible to do it with css?我不是很懂js,可以用css做吗?

            <p class="subtitle">
                Hemos enviado un correo electrónico a<br />
                <b>{{ capturedEmail }}</b> con las instrucciones<br />
                para la recuperación de tu contraseña.<br />
                Una vez reestablezcas la contraseña, podrás<br />
                ingresar a la plataforma con tus datos.
            </p>

In the code snippet above, the {{ capturedEmail }} is who I want to add that property在上面的代码片段中,{{ capturedEmail }} 是我要添加该属性的人

Example:例子:

correo@mail.com -> C***@mail.com correo@mail.com -> C***@mail.com

You can use an Angular Pipe for it.您可以为此使用 Angular Pipe。 Attached herewith is a Stackblitz Demo for your reference随附Stackblitz Demo供您参考

<h1>{{ capturedEmail | emailAsterisk }}</h1>
@Pipe({ name: 'emailAsterisk' })
export class EmailAsteriskPipe implements PipeTransform {

  transform(value: string): string {
    return value 
      ? value.replace(/\B.+@/g, (c, ) => c.split('').slice(0, -1).map(v => '*').join('') + '@') 
      : value;
  }

}

Result结果

correo@mail.com         >    c*****@mail.com
john.wick22@gmail.com   >    j**********@gmail.com

Basically you try to mask the email with asteriks, so pass any email to following this will solve your problem.基本上你尝试用星号掩盖 email,所以将任何 email 传递给以下将解决你的问题。

Try this below javascript code!试试下面的 javascript 代码!

 const capturedEmail = function (emailAddress, callback) { function mask(str) { var strLen = str.length; if (strLen > 4) { return str.substr(0, 1) + str.substr(1, strLen - 1).replace(/\w/g, '*') + str.substr(-1,1); } return str.replace(/\w/g, '*'); } return emailAddress.replace(/([\w.]+)@([\w.]+)(\.[\w.]+)/g, function (m, p1, p2, p3) { return callback(null,mask(p1) + '@' + p2 + p3); }); } capturedEmail('random string username@example.com test', function(err,res){ console.log(res); });

Result: u*******e@example.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM