美文网首页
ionic 3 隐藏手机号中间几项

ionic 3 隐藏手机号中间几项

作者: simonXX | 来源:发表于2018-08-09 09:55 被阅读0次

import {Pipe} from '@angular/core';

// Tell Angular2 we're creating a Pipe with TypeScript decorators
@Pipe({
  name: 'hidePhonePipe',
})
export class hidePhonePipe{

  // Transform is the new "return function(value, args)" in Angular 1.x
  transform(value, args?) {  
    if(value ==null){
      console.log("value");
    }else{
      if(value.length > 11){
        var reg = /^(\S*)(\S{4})(\S{4})$/;
        return  value.replace(reg, "$1****$3");
      }
      else if(value.length == 11){
        let reg = /^(\S{3})(\S{4})(\S{4})$/;
        return  value.replace(reg, "$1****$3");
      }
      else if(value.length > 4){
        var reg = /^(\S*)(\S{4})$/;
        return  value.replace(reg, "****$2");
      }else{
        var reg = /^(\S*)(\S{1})$/;
        return  value.replace(reg, "**$2");
      }
    }
    
    
  }

}

相关文章

网友评论

      本文标题:ionic 3 隐藏手机号中间几项

      本文链接:https://www.haomeiwen.com/subject/xemeuxtx.html