现在的位置: 首页 > 综合 > 正文

验证邮箱的正则表达式

2018年05月24日 ⁄ 综合 ⁄ 共 305字 ⁄ 字号 评论关闭

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个字母以上

$:字符串尾部

抱歉!评论已关闭.