手机号码中间隐藏四位

1. 切割

phone = res.phone.substr(0, 3) + '****' + res.phone.substr(7)

2. 正则

s.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"); 

3. 隐藏邮箱:只显示@前面的首位和末位:

s.replaceAll("(\\w?)(\\w+)(\\w)(@\\w+\\.[a-z]+(\\.[a-z]+)?)", "$1****$3$4")) 

猜你喜欢

转载自blog.csdn.net/qq_38290251/article/details/83421069