Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html>

<head>
  <title>8_常用注册页面的表单实例(含验证).html</title>

  <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  <meta http-equiv="description" content="this is my page">
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">

  <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  <style type="text/css">
    body {
      /*background-image: url(https://imgchr.com/content/images/system/home_cover_1552414407320_3a5f92.jpg);*/
      background-image: url('https://cdn.jsdelivr.net/gh/yansheng836/photos/universe.jpg');
      /*https://imgchr.com/content/images/system/home_cover_1587121321656_fce672.jpg
 https://imgtu.com/content/images/system/home_cover_1601010270144_8921bc.jpg
     https://cdn.jsdelivr.net/gh/yansheng836/photos/universe.jpg
 
      */
      background-repeat: no-repeat;
      /* 当内容高度大于图片高度时,背景图像的位置相对于viewport固定 */
      background-attachment: fixed;
      /*此条属性必须设置否则可能无效*/
      /* 让背景图基于容器大小伸缩 */
      background-size: cover;
      /* 设置背景颜色,背景图加载过程中会显示背景色 */
      background-color: #CCCCCC;
    }

    #user_reg {
      font-family: 微软雅黑;
      font-size: 40px;
      text-align: center;
      margin-top: 200px;
    }

    form {
      width: 500px;
      /*设置宽度,方便使其居中*/
      margin: 40px auto auto auto;
      /*上右下左*/
      font-size: 25px;
    }

    input {
      height: 30px;
      width: 12em;
      margin-top: 5px;
      margin-bottom: 5px;
    }

    /*input标签下的属性选择器*/

    input[type="submit"],
    input[type="reset"] {
      height: 25px;
      width: 5em;
      margin-top: 5px;
      margin-left: 6px;
    }
  </style>
</head>

<script type="text/javascript">
  //onblur失去焦点事件,用户离开输入框时执行 JavaScript 代码:
  //函数1:验证邮箱格式
  function validate_username(username) {
    //定义正则表达式的变量:邮箱正则
    var emailReg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    //console.log(username);
    if (username != "" && username.search(emailReg) != -1) {
      document.getElementById("test_user").innerHTML = "<font color='green' size='3px'>√邮箱格式正确</font>";
    } else {
      document.getElementById("test_user").innerHTML = "<font color='red' size='3px'>邮箱格式错误</font>";
    }
  }
  //函数2:验证密码是否符合要求:匹配6位密码,由数字和字母组成:
  function validate_password(password) {
    //^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6-10}$
    //测试密码:12345y
    var passwordReg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6}$/;
    if (password != "" && password.search(passwordReg) != -1) {
      document.getElementById("test_pw").innerHTML = "<font color='green' size='3px'>√密码格式正确</font>";
    } else {
      document.getElementById("test_pw").innerHTML = "<font color='red' size='3px'>密码格式错误</font>";
      alert("密码有6位,由数字和字母组成!");
    }
  }
  //函数3:验证两次输入的密码是否一样
  function validate_password2(password2) {
    var password = document.getElementById("password").value;
    //测试:console.log(password);
    //测试:console.log(password2);
    if (password == "") {
      document.getElementById("is_test_pw").innerHTML = "<font color='red' size='3px'>密码不为空</font>";
    } else if (password == password2) {
      document.getElementById("is_test_pw").innerHTML = "<font color='green' size='3px'>√两次输入的密码相同</font>";
    } else {
      document.getElementById("is_test_pw").innerHTML = "<font color='red' size='3px'>两次输入的密码不相同</font>";
      console.log("密码有6位,由数字和字母组成!");
    }
  }
  //函数4:验证表单是否已经填好
  function validate_form() {
    var username = document.getElementById("username").value;
    var password = document.getElementById("password").value;
    var password2 = document.getElementById("password2").value;
    //console.log("表单填写正确,可以正常提交!");
    //这三个,如果任何一个有问题,都返回false
    //[email protected]		12345y
    var emailReg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    var passwordReg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6}$/;
    if (username != "" && emailReg.test(username)) {
      if (password != "" && passwordReg.test(password)) {
        if (password2 == password) {
          alert("信息填写正确,可以正常提交!");
          console.log("信息填写正确,可以正常提交!");
          return true;
        } else {
          alert("密码不一致,提交失败,请重新填写!");
          console.log("密码不一致,提交失败,请重新填写!");
          return false;
        }
      } else {
        alert("密码格式错误,提交失败,请重新填写!");
        console.log("密码格式错误,提交失败,请重新填写!");
        return false;
      }
    } else {
      alert("注册的账号不符合要求,提交失败,请重新填写!");
      console.log("注册的账号不符合要求,提交失败,请重新填写!");
      return false;
    }
  }
</script>

<body>
  <div id="user_reg">用户注册:</div>
  <form action="./servlet/RegisterServlet" method="post" name="form">
    <table>
      <tr>
        <td>请输入账号:</td>
        <td><input type="text" id="username" name="username" placeholder="只能用邮箱注册" onblur="validate_username(this.value)" /></td>
        <td id="test_user"></td>
      </tr>
      <tr>
        <td>请输入密码:</td>
        <td><input type="password" id="password" name="password" placeholder="6位密码由数字和字母组成" onblur="validate_password(this.value)" /></td>
        <td id="test_pw"></td>
      </tr>
      <tr>
        <td>请确认密码:</td>
        <td><input type="password" id="password2" name="password2" onblur="validate_password2(this.value)" /></td>
        <td id="is_test_pw"></td>
      </tr>
      <tr>
        <td></td>
        <td><input type="submit" id="submit_form" value="注册" onclick="return validate_form()" />
          <input type="reset" value="重置" />
        </td>
      </tr>
    </table>
  </form>
</body>

</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console