java正则表达式对数据脱敏_PFDYZ的博客-CSDN博客

  //邮箱信息脱敏处理        if(StringUtils.isNotEmpty(userInfosVO.getEmail())){            userInfosVO.setEmail(userInfosVO.getEmail().replaceAll("(\\w+)\\w{5}@(\\w+)", "$1***@$2"));        }        //手机号脱敏        if(StringUtils.isNotEmpty(userInfosVO.getPhone())){            userInfosVO.setPhone(userInfosVO.getPhone().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"));        }//身份证号脱敏String cardNo = user.getCardNo();        if (!Strings.isNullOrEmpty(cardNo)) {            String newCardNo = cardNo.replaceAll("(\\d{4})\\d{10}(\\w{4})", "$1*****$2");            user.setCardNo(newCardNo);        }
 public String desensitizationByRealName(String realName) {        // 去除真实姓名敏感信息        if (!Strings.isNullOrEmpty(realName)) {            if (realName.length() > 1) {                if (realName.length() == 2) {                    realName = realName.replaceAll("(\\w)(\\w)(\\w)", "$1*");                }                if (realName.length() > 2) {                    realName = realName.substring(0, 2) + "*";                }            }        }        return realName;    }
package com.**.system.dto; import lombok.Data;import org.hibernate.validator.constraints.Length;import javax.validation.constraints.NotEmpty;import javax.validation.constraints.Pattern; /** * description: 用户注册使用 * date: 2020/6/19 15:51 * version: 1.0 */@Datapublic class RegisterDTO {     @NotEmpty(message = "账号不能为空")    private String userName;      @NotEmpty(message = "用户密码不能为空")    @Length(min = 8,max = 20,message = "密码长度必须在8-20之间")    @Pattern(regexp = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{0,20}$" ,message = "密码需要由字母跟数字组成")    private String password;     /**     * 验证码     */    private String smsCode; }

原网址: 访问
创建于: 2021-07-13 16:04:25
目录: default
标签: 无

请先后发表评论
  • 最新评论
  • 总共0条评论