zoukankan      html  css  js  c++  java
  • 通用的前端注册验证

    <!DOCTYPE html>
    <html>

    <head>
    <meta charset="UTF-8">
    <title>注册验证</title>
    </head>

    <body>
    <h1>注册验证</h1>
    <b id="stuAddMess" style="color: red;"></b>
    <form action="register.html" method="post">
    <table border="1" cellpadding="0" width="20%">
    <tr>
    <td>用户名:</td>
    <td><input type="text" id="username" /></td>
    </tr>
    <tr>
    <td>密码:</td>
    <td><input type="password" id="password" /></td>
    </tr>
    <tr>
    <td>确认密码:</td>
    <td><input type="password" id="confirmpass" /></td>
    </tr>
    <tr>
    <td>验证码:</td>
    <td><input type="text" id="code" /></td>
    </tr>
    <tr>
    <td colspan="2" align="center">
    <input type="submit" id="submit" value="提交" /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="reset" id="reset" value="重置" />
    </td>
    </tr>
    </table>
    </form>
    <script>
    window.onload = function() {
    var reset = document.getElementById('reset');
    var fm = document.getElementsByTagName('form')[0];
    var stuAddMess = document.getElementById('stuAddMess');
    reset.onclick = function() {
    username.value = '';
    password.value = '';
    confirmpass.value = '';
    code.value = '';
    username.focus();
    };
    fm.onsubmit = function() {
    if(!/^w{6,20}$/.test(username.value)) { // 用户名验证
    stuAddMess.innerHTML = "* 用户名不合法!";
    username.value = "";
    username.focus();
    return false;
    }
    if(!/^w{6,20}$/.test(password.value)) { // 密码验证
    stuAddMess.innerHTML = "* 密码不合法!";
    password.value = ''; // 清空
    password.focus(); // 将焦点移动到表单字段
    return false;
    }
    if(password.value != confirmpass.value) { // 密码确认验证
    stuAddMess.innerHTML = "* 两次输入的密码不一致,请重新输入!";
    password.value = ''; // 清空
    confirmpass.value = ''; // 清空
    password.focus(); // 将焦点移动到表单字段
    return false;
    }
    if(!/^d{4}$/.test(code.value)) { // 验证码验证
    stuAddMess.innerHTML = "* 验证码错误!";
    code.value = ''; // 清空
    code.focus(); // 将焦点移动到表单字段
    return false;
    }
    return true;
    };
    };
    </script>
    </body>

    </html>

  • 相关阅读:
    uniGUI试用笔记(九)uniGUI执行程序部署有3种形式1
    CxGrid导出Excel时清除颜色的设置
    delphi 安卓程序如何读取外部配置文件
    cxgrid动态显示行号
    为Delphi程序增加UAC功能(管理员身份运行exe)
    delphi debug release区别是什么?
    启动程序的同时传参给接收程序(XE8+WIN764)
    iOS Development和iOS Distribution有什么区别
    4张图看懂delphi 10生成ipa和在iPhone虚拟器上调试(教程)
    使用Xcode 7 beta免费真机调试iOS应用程序
  • 原文地址:https://www.cnblogs.com/qubo520/p/7407286.html
Copyright © 2011-2022 走看看