zoukankan      html  css  js  c++  java
  • 用户名只能由字母或者数字组成(用户控件与HTML控件)

    <head runat="server">
        <title></title>
        <script type="text/javascript" language="JavaScript">
            function checkform() {
                if (document.getElementById('usrname').value == "") {
                    window.alert("请输入您的用户名!");
                    document.Log.usrname.focus();
                    return false;
                }
                var patrn = /^[a-zA-Z0-9 ]{5,20}$/;
                if (!patrn.exec(document.getElementById('usrname').value)) {
                    window.alert("用户名只能由字母或者数字组成,并且不能少于5个字符,不能大于20个字符!");
                    document.getElementById('usrname').focus();
                    return false
                }
                if (document.getElementById('passwd').value == "") {
                    window.alert("请输入您的密码!");
                    document.getElementById('passwd').focus();
                    return false;
                }
                if ((document.getElementById('passwd').value.length < 6) || (document.getElementById('passwd').value.length > 20)) {
                    window.alert("登录密码不能少于6个字符,不能多于20个字符!");
                    document.getElementById('passwd').focus();
                    return false;
                }
                Log.submit.disabled = true;
                return true;
            }
    </script>
    </head>

    方法一: HTML控件

    <body>
        <form id="form1" runat="server">
        <div>
            <input id="usrname" type="text"/>
            <input id="passwd" type="password" />
            <input id="Button1" type="button" value="提交" onclick="checkform()"/>
        </div>
        </form>
    </body>

    方法二:服务器控件

    <body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="usrname" runat="server"></asp:TextBox>
            <asp:TextBox ID="passwd" runat="server"></asp:TextBox>
            <asp:Button ID="Button2" runat="server" Text="Button" OnClientClick="checkform()"/>
        </div>
        </form>
    </body>

  • 相关阅读:
    人工智能发展与模型定制化趋势
    Merry Christmas-集成华为HMS ML Kit手部关键点识别来接住圣诞老人的礼物吧!
    快速构建ML Kit自定义模型,实现特定领域图像/文本分类
    华为consumeOwnedPurchase消耗接口返回-1错误码
    超简单集成华为恶意URL检测,保障用户访问安全
    深入解析 C# 的 String.Create 方法
    .NET 内存泄漏的争议
    Centos相关介绍 (连接别人)
    阿里云 Nginx.conf文件配置详解
    阿里云使用Nginx部署vue项目
  • 原文地址:https://www.cnblogs.com/ljan/p/2606778.html
Copyright © 2011-2022 走看看