ionic 3 隐藏手机号中间几项
2018-08-09 本文已影响0人
simonXX
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");
}
}
}
}