package com.css.common.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 判断EMAIL文件的格式
*
* @version 1.0
*
*/
public class EmailUtil {
/**
* 如果是正确的EMAIL则返回正确的EMAIL地址,如果是错误的则返回空字符串
*
* @param line EMAIL地址
* @return
*/
public static String parse(String line) {
Pattern p = Pattern.compile("[\\w[.-]]+@[\\w[.-]]+\\.[\\w]+");
Matcher m = p.matcher(line);
StringBuffer buf = new StringBuffer();
while (m.find()) {
buf.append(m.group());
}
return buf.toString();
}
/**
* 如果是正确的EMAIL地址则返回TRUE,如果是错误的EMAIL地址帅返回FALSE
*
* @param line EMAIL地址
* @return
*/
public static boolean validate(String line) {
Pattern p = Pattern.compile("[\\w[.-]]+@[\\w[.-]]+\\.[\\w]+");
Matcher m = p.matcher(line);
if (m.find()) {
return true;
} else {
return false;
}
}
public static void main(String[] args){
String go = EmailUtil.parse("zhangzenglun@163.com");
System.out.println("go="+go);
}
}