<!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>
960

被折叠的 条评论
为什么被折叠?



