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

    一 问题描述

    3个EditBox,每个允许输入1到6个英文字符或数字,按OK输入结束

    (通过输入字符串,返回正误信息)

    二 有效等价类和无效等价类划分:

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

    三 测试用例

    编号 输入 预期输出
    1

    String 1 = "123"

    String 2 = "thomas"

    String 3 = "Aa234"
    Correct
    2

    String 1 = ""

    String 2 = "arcane"

    String 3 = "ArcaneBlast"
    Invalid Input
    3

    String 1 = "695_sd"

    String 2 = "mage"

    String 3 = "Ac"
    Invalid Input
    4

    String 1 = "fire"

    String 2 = "233"

    String 3 = "i"
    Correct
    5

    String 1 = "frost"

    String 2 = "frost_orb"

    String 3 = "23"
    Invalid Input
    6

    String 1 = "arcanemissle"

    String 2 = "thomas"

    String 3 = "Aa234"
    Invalid Input
    7

    String 1 = "123"

    String 2 = "txsds"

    String 3 = "sdder2223"
    Invalid Input
    8

    String 1 = "12"

    String 2 = "th"

    String 3 = "Aa234"
    Correct
    9

    String 1 = ""

    String 2 = "pyroblast"

    String 3 = "334"
    Invalid Input
    10

    String 1 = "123"

    String 2 = "thomas"

    String 3 = "Aa234"
    Correct

    四 代码实现

    <html>
    <head>
    <script type="text/javascript">
    function test(){
    var input1=document.getElementById('input1').value;
    
    var input2=document.getElementById('input2').value;
    
    var input3=document.getElementById('input3').value;
    
    if(input1=="")
    {
    window.alert("Invalid Input");
    }
    else
    {
    var n=input1.length;
    reg=/^[a-zA-Z0-9_]+$/; 
    if(n<1||n>6)
    {
    window.alert("Invalid Input")
    }
    
    else if(!reg.test(input1)) 
    {
    window.alert("Invalid Input");
    } 
    }
    }
    
    if(input2=="")
    {
    window.alert("Invalid Input");
    }
    else
    {
    var n=input2.length;
    reg=/^[a-zA-Z0-9_]+$/; 
    if(n<1||n>6)
    {
    window.alert("Invalid Input")
    }
    
    else if(!reg.test(input2)) 
    {
    window.alert("Invalid Input");
    } 
    }
    }
    
    if(input3=="")
    {
    window.alert("Invalid Input");
    }
    else
    {
    var n=input3.length;
    reg=/^[a-zA-Z0-9_]+$/; 
    if(n<1||n>6)
    {
    window.alert("Invalid Input")
    }
    
    else if(!reg.test(input3)) 
    {
    window.alert("Invalid Input");
    } 
    }
    }
    
    
    </script>
    </head>
    
    <body>
    <input type="text" id="input1" value ="输入1" /><br/>
    <input type="text" id="input2" value =“输入2”/><br/>
    <input type="text" id="input3" value =“输入3”/><br/>
    <input type="button" onclick="test()" value="确定" />
    </body>
    </html>
  • 相关阅读:
    solr服务中集成IKAnalyzer中文分词器、集成dataimportHandler插件
    Solr_全文检索引擎系统
    MySQL设置字段的默认值为当前系统时间
    mybatis_常用标签
    mybatis_映射查询
    Vue核心知识——computed和watch的细节全面分析
    nrm的安装与使用
    Windows下安装及使用NVM
    github仓库添加MIT许可
    ES6——箭头函数与普通函数的区别
  • 原文地址:https://www.cnblogs.com/Lucasleiva/p/4375410.html
Copyright © 2011-2022 走看看