Blame view

users/src/main/java/com/yohoufo/user/helper/HideDataUtil.java 1.6 KB
qinchao authored
1 2
package com.yohoufo.user.helper;
qinchao authored
3
import com.yohoufo.common.utils.UserInfoHiddenHelper;
qinchao authored
4 5 6 7 8 9 10 11 12 13
import org.apache.commons.lang3.StringUtils;

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

public class HideDataUtil {

    public static boolean isEmail(String string) {
        if (string == null)
            return false;
14 15
        //String regEx1 = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        String regEx1 = "^([\\w]+[-|\\.]?)+[\\w]@([\\w]+(-[\\w]+)?\\.)+[a-zA-Z]{2,}$";
qinchao authored
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
        Pattern p;
        Matcher m;
        p = Pattern.compile(regEx1);
        m = p.matcher(string);
        if (m.matches())
            return true;
        else
            return false;
    }


    /**
     * 只显示@前面的首位和末位
     */
    public static String hideEmail(String email) {
        if(StringUtils.isBlank(email)) {
            return email;
        }
        //email =  email.replaceAll("(\\w?)(\\w+)(\\w)(@\\w+\\.[a-z]+(\\.[a-z]+)?)", "$1****$3$4");
        email =  email.replaceAll("([\\S\\s]{3}?)([\\S\\s]+)(@\\w+\\.[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+)?)", "$1****$3");
        return email;
    }

    public static void main(String args[]){
40 41
        String str="ff.f.wwwr3@163.com.com";
        System.out.println(isEmail(str));
qinchao authored
42 43
        System.out.println(hideEmail(str));
        str = "123";
qinchao authored
44 45
        System.out.println(UserInfoHiddenHelper.isPhone(str));
        System.out.println(UserInfoHiddenHelper.hidePhoneNo(str));
qinchao authored
46 47 48 49 50

        System.out.println(str.substring(0,1)+"****"+str.substring(str.length()-1));
    }

}