/** * 传入邮箱域名所有变为小写,然后拼接前缀返回 *<b>Summary: </b> * emailDomainTransform() * @param domain * @return * @throws Exception */ public static String emailDomainTransform(String email) throws Exception{ if(email == null || "".equals(email.trim()) || email.indexOf("@") == -1){ throw new Exception("验证邮箱地址错误"); } String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"; Pattern regex = Pattern.compile(check); Matcher matcher = regex.matcher(email); boolean flag = matcher.matches(); if(flag){ StringBuffer temp = new StringBuffer(); temp.append(email.trim().substring(0, email.trim().indexOf("@"))); temp.append((email.trim().indexOf("@") == email.trim().length() ?"":email.trim().substring(email.trim().indexOf("@"))).toLowerCase()); return temp.toString(); } else { throw new Exception("验证邮箱地址错误"); } }
StirngUtil工具类 之 邮箱注冊 域名不区分大写和小写方法
时间: 2024-10-27 11:15:30