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;
    }

}

技术分享图片

详细请看:
正则表达式-邮箱有效性验证

Java 校验EMAIL格式方法,真为正确

以上是关于email 校验的主要内容,如果未能解决你的问题,请参考以下文章

代码片段:Shell脚本实现重复执行和多进程

C# 校验Email(电子邮件)地址是否合法

Java44旅游案例:邮箱激活,登录校验

怎么快速对DB里的所有email进行校验

个人技术总结 --- 基于SpringBoot使用Email进行验证码校验

Android App 安全的HTTPS 通信