HideDataUtil.java
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.yohoufo.user.helper;
import com.yohoufo.common.utils.UserInfoHiddenHelper;
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;
//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,}$";
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="ff.f.wwwr3@163.com.com";
System.out.println(isEmail(str));
System.out.println(hideEmail(str));
str = "123";
System.out.println(UserInfoHiddenHelper.isPhone(str));
System.out.println(UserInfoHiddenHelper.hidePhoneNo(str));
System.out.println(str.substring(0,1)+"****"+str.substring(str.length()-1));
}
}