zoukankan      html  css  js  c++  java
  • 正则表达式验证输入用户名格式是否正确

    有效等价类和无效等价类:

    有效等价类 无效等价类
    length=[1-6] length=0 or length>6
    char=[a-zA-Z0-9] other chars

    登录图片如图所示:

    <html>
    <head>
    <script type="text/javascript">
    function test(){
       var username=document.getElementById('username').value;
       if(username=="")
       {
            window.alert("输入用户名不能为空,请重新输入");
       }
       else
       {
           var n=username.length;
           reg=/^[a-zA-Z0-9_]+$/; 
           if(n<1||n>6)
           {
               window.alert("用户名长度不正确")
           }
    
           else if(!reg.test(username))          
           {
               window.alert("用户名非法");
           } 
       }
    }
    </script>
    </head>
    
    <body>
    <input type="text" id="username" name ="用户名:" /><br/>
    <input type="text" id="password" name =“密码:”/><br/>
    <input type="text" id="certify" name =“验证码:”/><br/>
    <input type="button" onclick="test()" value="登录" />
    </body>
    </html>

    测试用例:

    测试用例 是否有效
    aaa 有效
    z01a 有效
      无效
    yu;a 无效
    alexander 无效
    0077 有效
    b53123 有效
    比尔 无效
    lem_sa 无效
    shenmegui 无效
    z111 有效
    p 有效
    10000000 无效
    123 有效
    zzh 有效
  • 相关阅读:
    Linux基础命令(一)
    You've made choice
    protege推理
    字符编码
    第二次作业
    数据类型-集合set
    数据类型-元组&字典
    数据类型-列表
    数据类型-数值&字符串
    流程控制之for循环
  • 原文地址:https://www.cnblogs.com/Lucasleiva/p/4356878.html
Copyright © 2011-2022 走看看