All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zhibaocloud.carbon.intg.desensitization.CarbonPhoneDesensitization Maven / Gradle / Ivy

Go to download

智保云投保通道开发 SDK。定义数据模型以及数据交互所支持的加解密方法

The newest version!
package com.zhibaocloud.carbon.intg.desensitization;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author yangtuo
 */
public class CarbonPhoneDesensitization implements CarbonStringDesensitization {

  /**
   * 手机号正则
   */
  private static final Pattern DEFAULT_PATTERN = Pattern.compile(
      "(13[0-9]|14[579]|15[0-3,5-9]|166|17[0135678]|18[0-9]|19[89])\\d{8}");

  /**
   * 手机号脱敏 只保留前3位和后4位
   */
  @Override
  public String desensitize(String original) {
    Matcher matcher = DEFAULT_PATTERN.matcher(original);
    while (matcher.find()) {
      String group = matcher.group();
      original = original.replace(group,
          group.substring(0, 3) + Symbol.getSymbol(4, Symbol.STAR) + group.substring(7, 11));
    }
    return original;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy