email 校验
Posted hglibin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了email 校验相关的知识,希望对你有一定的参考价值。
email 校验:
javascript: /^([a-zA-Z0-9_-])[email protected]([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/
java: ^([a-zA-Z0-9_-])[email protected]([a-zA-Z0-9_-])+((\\.[a-zA-Z0-9_-]{2,3}){1,2})$
一段小代码:
public class Demo {
public static void main(String[] args) {
System.out.println("满足逻辑的:");
System.out.println("[email protected]: " + emailFormat("[email protected]"));
System.out.println("[email protected]: " + emailFormat("[email protected]"));
System.out.println("不满足校验逻辑:");
System.out.println("[email protected]: " + emailFormat("[email protected]"));
System.out.println("[email protected]: " + emailFormat("[email protected]"));
System.out.println("[email protected],com: " + emailFormat("[email protected],com"));
System.out.println("[email protected]: " + emailFormat("[email protected]"));
System.out.println("[email protected]?q?.com: " + emailFormat("[email protected]?q?.com"));
System.out.println("[email protected]@qq.com: " + emailFormat("[email protected]@qq.com"));
System.out.println("[email protected]@139.com: " + emailFormat("[email protected]@139.com"));
System.out.println("[email protected]。com.cn: " + emailFormat("[email protected]。com.cn"));
System.out.println("[email protected])m: " + emailFormat("[email protected])m"));
System.out.println("[email protected]?£QQ.COM: " + emailFormat("[email protected]?£QQ.COM"));
System.out.println("[email protected]_.com.cn: " + emailFormat("[email protected]_.com.cn (严格版校验不通过)"));
System.out.println("[email protected]_163sadasdf.com.cn: " + emailFormat("[email protected]_163sadasdf.com.cn (严格版校验不通过)"));
}
public static boolean emailFormat(String email) {
String regStr = "^([a-zA-Z0-9_-])[email protected]([a-zA-Z0-9_-])+((\\.[a-zA-Z0-9_-]{2,3}){1,2})$";
boolean tag = true;
if (!email.matches(regStr)) {
tag = false;
}
return tag;
}
}
详细请看:
正则表达式-邮箱有效性验证
以上是关于email 校验的主要内容,如果未能解决你的问题,请参考以下文章