Commit 8e3a203c authored by 董建华's avatar 董建华

增加校验

parent 979e976e
...@@ -55,7 +55,6 @@ public class AddressFilter { ...@@ -55,7 +55,6 @@ public class AddressFilter {
} }
/** /**
* 是否包含特殊字符 * 是否包含特殊字符
* *
...@@ -95,38 +94,42 @@ public class AddressFilter { ...@@ -95,38 +94,42 @@ public class AddressFilter {
//替换email //替换email
public static String getEmail(String phone,String email) { public static String getEmail(String phone, String email) {
//去掉所有的空白
if(null != email){ if (null != email) {
email = email.replaceAll("\\s",""); //去掉所有的空白
email = email.replaceAll("\\s", "");
//替换首尾中文
Matcher matcher = CHINA_PATTERN.matcher(email); Matcher matcher = CHINA_PATTERN.matcher(email);
if(matcher.find()){ if (matcher.find()) {
email = matcher.replaceAll(""); email = matcher.replaceAll("");
} }
} }
//去掉空白和首尾中文后在判断是否合法
if(isEmail(email)){ if (isEmail(email)) {
return email; return email;
} }
if( null == phone){ //如果还不合法那么用手机号替换
if (null == phone) {
return null; return null;
} }
String phonePre = phone; String phonePre = phone;
if(phone.length()>3){ if (phone.length() > 3) {
phonePre = phone.substring(0, 3); phonePre = phone.substring(0, 3);
} }
Set<Map.Entry<List<String>, String>> entries = OPERATO_MAP.entrySet(); Set<Map.Entry<List<String>, String>> entries = OPERATO_MAP.entrySet();
for (Map.Entry<List<String>, String> entry : entries) { for (Map.Entry<List<String>, String> entry : entries) {
boolean contains = entry.getKey().contains(phonePre); boolean contains = entry.getKey().contains(phonePre);
if(contains){ if (contains) {
return phone.concat(entry.getValue()); return phone.concat(entry.getValue());
} }
} }
return phone.concat(UNICOM_SUFFIX); return phone.concat(UNICOM_SUFFIX);
} }
//校验是否是邮箱 //校验是否是邮箱
public static boolean isEmail(String email){ public static boolean isEmail(String email) {
if(null == email){ if (null == email) {
return false; return false;
} }
Matcher matcher = EMAIL_PATTERN.matcher(email); Matcher matcher = EMAIL_PATTERN.matcher(email);
...@@ -140,5 +143,4 @@ public class AddressFilter { ...@@ -140,5 +143,4 @@ public class AddressFilter {
private String target; private String target;
private String replaceMent; private String replaceMent;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment