String pat = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{3,}$"; Pattern p = Pattern.compile(pat); Matcher m = p.matcher(email); // 邮箱格式不对 if (!m.matches()) { Toast.makeText(context, "邮箱格式不正确", Toast.LENGTH_SHORT).show(); return false; }
^:字符串头部
[a-z0-9A-Z]:表示大小写字母和数字
[a-zA-Z]{3,}:3个字母以上
$:字符串尾部