邮箱验证工具

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>邮箱验证工具</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 600px;
            margin: 0 auto;
            padding: 20px;
            line-height: 1.6;
        }
        .container {
            background-color: #f9f9f9;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            text-align: center;
        }
        input[type="email"] {
            width: 100%;
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 15px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        button:hover {
            background-color: #45a049;
        }
        #result {
            margin-top: 20px;
            padding: 10px;
            border-radius: 4px;
        }
        .valid {
            background-color: #dff0d8;
            color: #3c763d;
        }
        .invalid {
            background-color: #f2dede;
            color: #a94442;
        }
        .footer {
            margin-top: 30px;
            text-align: center;
            font-size: 12px;
            color: #666;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>邮箱验证工具</h1>
        <p>请输入要验证的邮箱地址:</p>
        <input type="email" id="emailInput" placeholder="example@domain.com">
        <button onclick="validateEmail()">验证邮箱</button>
        <div id="result"></div>
    </div>

    <div class="footer">
    </div>

    <script>
        function validateEmail() {
            const email = document.getElementById('emailInput').value;
            const resultDiv = document.getElementById('result');
            
            // 简单的正则表达式验证
            const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
            
            if (emailRegex.test(email)) {
                // 进一步验证域名部分
                const domain = email.split('@')[1];
                if (domain.includes('.')) {
                    resultDiv.textContent = `邮箱 ${email} 格式有效!`;
                    resultDiv.className = 'valid';
                } else {
                    resultDiv.textContent = '邮箱域名无效,缺少顶级域名(如 .com, .net 等)';
                    resultDiv.className = 'invalid';
                }
            } else {
                resultDiv.textContent = '邮箱格式无效,请检查后重试!';
                resultDiv.className = 'invalid';
            }
        }
        
        // 添加回车键触发验证
        document.getElementById('emailInput').addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                validateEmail();
            }
        });
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值