zoukankan      html  css  js  c++  java
  • 个人信息 手机号、身份证 姓名脱敏加密打码替换*

    //个人信息 手机号或证件号打码
      private String getEncrypt(String number){
        //电话
        if (number != null && number.length() == 11) {
          return number.replaceAll("(\d{3})\d{4}(\d{4})", "$1****$2");
        }
        //身份证号码
        if (number != null && number.length() == 18) {
          return number.replaceAll("(\d{4})\d{12}(\w{2})","$1************$2");
        } else if(number != null && number.length() == 15){
          return number.replaceAll("(\d{4})\d{9}(\w{2})","$1*********$2");
        }else{
          return number;
        }
      }
    
    
    
    
    
    
    //名字打码
    private String getEncryptName(String name){
        String regex = "[\u4E00-\u9FA5]{2,30}(?:·[\u4E00-\u9FA5]{2,5})*";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(name);
        boolean isMatch = m.matches();
        StringBuilder sb = new StringBuilder();
        String names="";
        if (isMatch) {//说明是中文姓名
          if (name.contains("·")) {
            String[] strNames = name.split("·");
            for (int i = 0; i < strNames.length-1; i++) {
              if (i!=strNames.length) {
                names = strNames[i].replaceAll("[\u4e00-\u9fa5]", "*");
              }
              sb.append(names).append("·");
            }
            return sb.append(strNames[strNames.length-1]).toString();
          } else {
            String[] strNames = name.split("");
            sb.append(strNames[1]);
            for (int i = 2; i < strNames.length; i++) {
              names = strNames[i].replaceAll("[\u4e00-\u9fa5]", "*");
              sb.append(names);
            }
            return sb.toString();
          }
        } else {//说明是英文
          if (name.contains(" ")) {
            String[] strNames = name.split(" ");
            for (int i = 0; i < strNames.length-1; i++) {
              if (i!=strNames.length) {
                names = strNames[i].replaceAll("^[A-Za-z]+$", "*");
              }
              sb.append(names).append(" ");
            }
            return sb.append(strNames[strNames.length-1]).toString();
          }
        }
        return name;
      }
  • 相关阅读:
    Vue+element tree使用,当弹窗关闭时,this.$refs.tree.setCheckedKeys([])不能清空选中
    npm ERR! A complete log of this run can be found in
    Vue面试题之vue实现MVVM数据绑定
    渐变色的ie兼容
    安徽地图
    数组去重的四种方法
    EF Code First创建数据库
    Code First Migrations更新数据库结构(数据迁移)
    Bootstrap 样式大全
    C#程序中:如何向记事本中写入内容和导出内容
  • 原文地址:https://www.cnblogs.com/pan-my/p/13806904.html
Copyright © 2011-2022 走看看