|
|
package com.yohoufo.user.helper;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
public class HideDataUtil {
|
|
|
|
|
|
/**
|
|
|
* 11位数字
|
|
|
*/
|
|
|
public static boolean isPhone(String phoneNo){
|
|
|
if (phoneNo == null)
|
|
|
return false;
|
|
|
|
|
|
String regEx = "^(\\d{11})$";
|
|
|
//String regEx2 = "^[0-9_]+$";//纯数字
|
|
|
Pattern pattern = Pattern.compile(regEx);
|
|
|
Matcher matcher = pattern.matcher(phoneNo);
|
|
|
|
|
|
return matcher.matches();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* 方法描述 隐藏手机号中间位置字符,显示前三后三个字符
|
|
|
*
|
|
|
*/
|
|
|
public static String hidePhoneNo(String phoneNo) {
|
|
|
if(StringUtils.isBlank(phoneNo)) {
|
|
|
return phoneNo;
|
|
|
}
|
|
|
|
|
|
phoneNo = phoneNo.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
|
|
|
|
|
|
return phoneNo;
|
|
|
}
|
|
|
|
|
|
|
|
|
public static boolean isEmail(String string) {
|
|
|
if (string == null)
|
|
|
return false;
|
|
|
String regEx1 = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
|
|
|
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[]){
|
|
|
String str="f f.f.wwwr3@163.COM.COM";
|
|
|
System.out.println(hideEmail(str));
|
|
|
str = "123";
|
|
|
System.out.println(isPhone(str));
|
|
|
System.out.println(hidePhoneNo(str));
|
|
|
|
|
|
System.out.println(str.substring(0,1)+"****"+str.substring(str.length()-1));
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|