使用jQuery写一个注册界面

写一个注册页面,包含用户名、密码、二次输入密码、邮箱地址。
必须校验内容:
1. 用户名必须包含英文字母和数字;
2. 密码必须大于6位;
3. 两次密码必须一致;
4. 邮箱必须包含.com和@符号,@符号后必须是:gmail、163、qq、woniu其中之一;
5. 用户名、密码、二次输入密码、邮箱都不能为空。
 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="../../pack/bootstrap/css/bootstrap.min.css"/>
    <script type="text/javascript" src="../js/jquery-3.6.3.js"></script>
    <style>

        body{
            background-image: url("../img/q.jpg");
            background-repeat: no-repeat;
            background-attachment: fixed;
            background-size: cover;
        }
        .login-frame {
            width: 450px;
            height: 500px;
            margin-top: 200px;
        }

        .login-head {
            width: 450px;
            height: 70px;
            background-color: rgba(37, 169, 210, 0.80);
            text-align: center;
            line-height: 100px;
            font-size: 10px;
            font-weight: bold;
            color: rgba(245, 245, 245, 0.90);
            padding-top: 1px;
            border-top-left-radius: 15px;
            border-top-right-radius: 15px;
        }

        .login-
  • 0
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
以下是一个简单的注册验证界面的示例代码: HTML代码: ``` <!DOCTYPE html> <html> <head> <title>注册验证界面</title> <meta charset="UTF-8"> <link href="style.css" rel="stylesheet"> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="script.js"></script> </head> <body> <h1>注册验证界面</h1> <form id="register-form" method="post" action=""> <label for="username">用户名:</label> <input type="text" id="username" name="username" required> <div id="username-error" class="error-message"></div> <label for="email">邮箱:</label> <input type="email" id="email" name="email" required> <div id="email-error" class="error-message"></div> <label for="password">密码:</label> <input type="password" id="password" name="password" required> <div id="password-error" class="error-message"></div> <label for="confirm-password">确认密码:</label> <input type="password" id="confirm-password" name="confirm-password" required> <div id="confirm-password-error" class="error-message"></div> <input type="submit" value="注册"> </form> </body> </html> ``` CSS代码: ``` body { font-family: Arial, sans-serif; background-color: #f0f0f0; } h1 { text-align: center; margin-top: 50px; } form { width: 400px; margin: 0 auto; padding: 20px; background-color: #fff; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); } label { display: block; margin-bottom: 5px; } input[type="text"], input[type="email"], input[type="password"] { display: block; width: 100%; padding: 10px; margin-bottom: 10px; border: none; border-radius: 3px; box-shadow: 0 0 5px rgba(0, 0, 0, 0.1); } input[type="submit"] { display: block; width: 100%; padding: 10px; margin-top: 20px; background-color: #4CAF50; color: #fff; border: none; border-radius: 3px; cursor: pointer; } .error-message { color: #f00; font-size: 12px; margin-bottom: 10px; } ``` jQuery代码: ``` $(document).ready(function() { // 验证用户名 $("#username").blur(function() { var username = $(this).val(); if (username.trim() == "") { $("#username-error").text("用户名不能为空"); } else if (username.length < 6 || username.length > 20) { $("#username-error").text("用户名长度应为6-20个字符"); } else { $("#username-error").text(""); } }); // 验证邮箱 $("#email").blur(function() { var email = $(this).val(); if (email.trim() == "") { $("#email-error").text("邮箱不能为空"); } else if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(email)) { $("#email-error").text("邮箱格式不正确"); } else { $("#email-error").text(""); } }); // 验证密码 $("#password").blur(function() { var password = $(this).val(); if (password.trim() == "") { $("#password-error").text("密码不能为空"); } else if (password.length < 6 || password.length > 20) { $("#password-error").text("密码长度应为6-20个字符"); } else { $("#password-error").text(""); } }); // 验证确认密码 $("#confirm-password").blur(function() { var confirmPassword = $(this).val(); var password = $("#password").val(); if (confirmPassword.trim() == "") { $("#confirm-password-error").text("确认密码不能为空"); } else if (confirmPassword != password) { $("#confirm-password-error").text("两次密码输入不一致"); } else { $("#confirm-password-error").text(""); } }); // 提交表单时验证 $("#register-form").submit(function() { var username = $("#username").val(); var email = $("#email").val(); var password = $("#password").val(); var confirmPassword = $("#confirm-password").val(); if (username.trim() == "") { $("#username-error").text("用户名不能为空"); return false; } else if (username.length < 6 || username.length > 20) { $("#username-error").text("用户名长度应为6-20个字符"); return false; } else if (email.trim() == "") { $("#email-error").text("邮箱不能为空"); return false; } else if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(email)) { $("#email-error").text("邮箱格式不正确"); return false; } else if (password.trim() == "") { $("#password-error").text("密码不能为空"); return false; } else if (password.length < 6 || password.length > 20) { $("#password-error").text("密码长度应为6-20个字符"); return false; } else if (confirmPassword.trim() == "") { $("#confirm-password-error").text("确认密码不能为空"); return false; } else if (confirmPassword != password) { $("#confirm-password-error").text("两次密码输入不一致"); return false; } else { return true; } }); }); ``` 在这个示例中,我们使用HTMLCSSjQuery来创建一个简单的注册验证界面。在表单中,我们为每个输入字段添加了必要的验证规则,例如,用户名不能为空且长度应为6-20个字符,电子邮件地址必须符合标准格式,密码不能为空且长度应为6-20个字符,确认密码必须与密码相匹配。 我们使用jQuery的事件处理程序来验证每个输入字段,并在需要时显示错误消息。在提交表单时,我们还验证了每个输入字段,并在表单未通过验证时阻止提交。 这只是一个简单的示例,您可以根据需要添加更多的验证规则和样式来创建自定义的注册验证界面

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

子鱼.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值