js实现邮箱验证信息

<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
<head>

</head>
<body>
    <label>email:</label><input type="text" id="email"/>
    <input type="button" value="验证" onclick="checkemail()" />
    <span id="message"></span>
</body>
<script type="text/javascript">
    
    function checkemail() {
        var obj = document.getElementById("email");
        if(obj.value != ""){
            var str = obj.value;
            if(str.indexOf("@") != -1 && str.indexOf(".") != -1){
                var a = str.split("@");
                if(a[0].length > 0){
                    if(a[1].length > 0){
                        var b = a[1].split(".");
                        if(b[0].length > 0){
                            if(b[1].length > 1){
                                document.getElementById("message").innerHTML = "<font color='green'>正确</font>";
                            }
                            else{
                                document.getElementById("message").innerHTML = "<font color='red'>错误,.后面必须要有至少2个字符!!!</font>";
                            }
                        }
                        else{
                            document.getElementById("message").innerHTML = "<font color='red'>错误,@和.之间必须要有至少1个字符!!!</font>";
                        }
                    }
                    else{
                        document.getElementById("message").innerHTML = "<font color='red'>错误,@后面必须要有至少1个字符!!!</font>";
                    }
                }
                else{
                    document.getElementById("message").innerHTML = "<font color='red'>错误,@前面必须要有至少1个字符!!!</font>";
                }
            }
            else{
                document.getElementById("message").innerHTML = "<font color='red'>错误,邮箱需要包含@和.字符!!!</font>";
            }
        }
    }

</script>

</html>
上一篇:11. 约束


下一篇:疏水膜的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告