//用来判断e-mail地址的一个范例代码
//e-mail域名的正规表现 private static Pattern PATTERN_EMAIL_DOMAIN_PART = Pattern.compile("^([a-zA-Z0-9][a-zA-Z0-9_-]{0,61}[a-zA-Z0-9]|[a-zA-Z0-9])$"); //e-mailID的正规表现 private static Pattern PATTERN_EMAIL_LOCAL = Pattern.compile("^([a-zA-Z0-9_-][a-zA-Z0-9_//.-]*[a-zA-Z0-9_-]|[a-zA-Z0-9_-])$"); //e-mail最大长度 private static int EMAIL_MAX_LENGTH = 128; public static boolean checkEmail(String email) { // 长度检测 if (email.length() > EMAIL_MAX_LENGTH) { return false; } // '@'个数检测 String token[] = tokenize(email, "@"); if (token.length != 2) { return false; } // '.'个数检测 String local = token[0]; String domain = token[1]; token = tokenize(domain, "."); if (token.length <= 1) { return false; } // '.'位置检测 // ドメインは、63文字以下、先頭末尾が英数字、それ以外が英数字"-","_" for (int i = 0; i < token.length; i++) { if (PATTERN_EMAIL_DOMAIN_PART.matcher(token[i]).matches() == false) { return false; } } // ID的先头和末尾文字串为英文、数字"-","_"、其他位置的文字串为英文、数字"-","_","." if (PATTERN_EMAIL_LOCAL.matcher(local).matches() == false) { return false; } return true; }