java正则表达式判断Email格式

2/22/2017来源:ASP.NET技巧人气:3038

输入:

public class JudgeEmail {

	public static void main(String[] args) {
		//定义要匹配的Email地址的正则表达式
		String regex="\\[email protected]\\w+(\\.\\w+)+";
		String str1="[email protected]";
		String str2="[email protected]QQ.com";
		String str3="[email protected]";
		String str4="[email protected]";
		if (str1.matches(regex)) 
			System.out.PRintln("1");
		if (str2.matches(regex)) 
			System.out.println("2");
		if (str3.matches(regex)) 
			System.out.println("3");
		if (str4.matches(regex)) 
			System.out.println("4");

	}

}
输出: