Java 邮箱判断 正则表达式

import java.util.Scanner;



public final class EmailCheck
{
	public static boolean checkEmail(String email)
	{
		String regex1 = "[a-zA-Z]+[a-zA-Z0-9_]*@[a-zA-Z0-9]+[.][a-zA-Z0-9]+";
		//字母开头,@后加字母或数字,后面加点,后面字母或数字
		String regex2 = "[a-zA-Z]+[a-zA-Z0-9_]*@[a-zA-Z0-9]+[.][a-zA-Z0-9]+[.][a-zA-Z0-9]+";
		//..........在regex1基础上,后面加.和其他字母组成的后缀
		
		if(email.matches(regex1) || email.matches(regex2))
		{
			System.out.println("合法邮箱地址");
			return true;
		}
		else
		{
			System.out.println("不合法邮箱地址");
			return false;
		}
	}
	public static boolean checkabc(String email)
	{
		//判断是否包含 某字符串,判断是某个网站的邮箱
		if(email.indexOf("@abc.com") > -1)
		{
			System.out.println("abc");
			return true;
		}
		else
		{
			System.out.println("非abc");
			return false;
		}
	}
}

class Entry
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		String email = input.next();
		EmailCheck.checkEmail(email);
		EmailCheck.checkabc(email);
	}
}

你可能感兴趣的:(JAVA)