设计一个用户注册页面,显示当前日期、时间和星期几。注册内容包括用户名,密码及密码确认框,性别,邮箱,手机号码,一个提交按钮,一个重写按钮(清空所有文本框内容 )。要求检测密码长度为8-12位,检测密码组成需由英文大小写字母和数字组成,检测邮箱格式是否正确,检测手机号码是否是11位。
时间: 2024-03-22 19:41:07 浏览: 169
设计用户注册页面
好的,这是一个前端页面设计的问题,我可以给你提供一个示例代码,你可以参考下面的代码进行开发。
```html
<!DOCTYPE html>
<html>
<head>
<title>User Registration</title>
<meta charset="utf-8">
<script type="text/javascript">
function checkPassword() {
var password = document.getElementById("password").value;
var confirmPassword = document.getElementById("confirmPassword").value;
if(password !== confirmPassword) {
alert("两次密码输入不一致,请重新输入!");
return false;
}
if(password.length < 8 || password.length > 12) {
alert("密码长度应为8-12位!");
return false;
}
if(!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,12}$/.test(password)) {
alert("密码需由英文大小写字母和数字组成!");
return false;
}
return true;
}
function checkEmail() {
var email = document.getElementById("email").value;
if(!/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+$/.test(email)) {
alert("邮箱格式不正确,请重新输入!");
return false;
}
return true;
}
function checkPhone() {
var phone = document.getElementById("phone").value;
if(phone.length !== 11) {
alert("手机号码应为11位,请重新输入!");
return false;
}
return true;
}
function checkForm() {
if(!checkPassword() || !checkEmail() || !checkPhone()) {
return false;
}
return true;
}
function resetForm() {
document.getElementById("username").value = "";
document.getElementById("password").value = "";
document.getElementById("confirmPassword").value = "";
document.getElementById("male").checked = false;
document.getElementById("female").checked = false;
document.getElementById("email").value = "";
document.getElementById("phone").value = "";
}
function showTime() {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1;
var date = now.getDate();
var day = now.getDay();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
var week = ["日", "一", "二", "三", "四", "五", "六"];
document.getElementById("time").innerHTML = year + "年" + month + "月" + date + "日 " + "星期" + week[day] + " " + hour + ":" + minute + ":" + second;
setTimeout(showTime, 1000);
}
</script>
</head>
<body onload="showTime()">
<h1>User Registration</h1>
<p id="time"></p>
<form action="#" onsubmit="return checkForm()">
<label for="username">用户名:</label>
<input type="text" id="username" name="username" required><br><br>
<label for="password">密码:</label>
<input type="password" id="password" name="password" required><br><br>
<label for="confirmPassword">确认密码:</label>
<input type="password" id="confirmPassword" name="confirmPassword" required><br><br>
<label for="gender">性别:</label>
<input type="radio" id="male" name="gender" value="male" required>
<label for="male">男</label>
<input type="radio" id="female" name="gender" value="female" required>
<label for="female">女</label><br><br>
<label for="email">邮箱:</label>
<input type="email" id="email" name="email" required><br><br>
<label for="phone">手机号码:</label>
<input type="tel" id="phone" name="phone" required><br><br>
<input type="submit" value="提交">
<input type="button" value="重写" onclick="resetForm()">
</form>
</body>
</html>
```
上面的代码中,我们使用了 JavaScript 来实现表单验证和重写的功能,具体实现细节见注释。同时,我们还使用了 JavaScript 中的 Date 对象来显示当前的日期、时间和星期几。你可以将这段代码保存为一个 HTML 文件,并在浏览器中打开,就可以看到一个用户注册页面了。
阅读全文