Commit 6726bf85 authored by 董建华's avatar 董建华

增加去掉首尾汉字的正则

parent f7694f9f
...@@ -36,6 +36,9 @@ public class AddressFilter { ...@@ -36,6 +36,9 @@ public class AddressFilter {
//邮箱正则 //邮箱正则
private static Pattern EMAIL_PATTERN = Pattern.compile("^[A-Za-z0-9]+([._\\-]*[A-Za-z0-9])*@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$"); private static Pattern EMAIL_PATTERN = Pattern.compile("^[A-Za-z0-9]+([._\\-]*[A-Za-z0-9])*@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$");
//首尾中文
private static Pattern CHINA_PATTERN = Pattern.compile("^[\u4e00-\u9fa5]+|[\u4e00-\u9fa5]+$");
static { static {
synchronized (AddressFilter.class) { synchronized (AddressFilter.class) {
if (PATTERN_LIST.size() == 0) { if (PATTERN_LIST.size() == 0) {
...@@ -96,6 +99,10 @@ public class AddressFilter { ...@@ -96,6 +99,10 @@ public class AddressFilter {
//去掉所有的空白 //去掉所有的空白
if(null != email){ if(null != email){
email = email.replaceAll("\\s",""); email = email.replaceAll("\\s","");
Matcher matcher = CHINA_PATTERN.matcher(email);
if(matcher.find()){
email = matcher.replaceAll("");
}
} }
if(isEmail(email)){ if(isEmail(email)){
...@@ -121,6 +128,7 @@ public class AddressFilter { ...@@ -121,6 +128,7 @@ public class AddressFilter {
Matcher matcher = EMAIL_PATTERN.matcher(email); Matcher matcher = EMAIL_PATTERN.matcher(email);
return matcher.matches(); return matcher.matches();
} }
@Getter @Getter
@Setter @Setter
@AllArgsConstructor @AllArgsConstructor
...@@ -129,4 +137,8 @@ public class AddressFilter { ...@@ -129,4 +137,8 @@ public class AddressFilter {
private String replaceMent; private String replaceMent;
} }
public static void main(String[] args) {
String email = getEmail("18518759303", "啊412763575@qq.com董建华");
System.out.println(email);
}
} }
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