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>
  • 相关阅读:
    PHPStrom 转 VSCode 折腾记录(配置分享)
    Ubuntu 17.10/18.04使用内置指纹识别(联想T440内置Synaptics Validity Sensors)
    How to Enable Fingerprint Login In Ubuntu 19.10, 19.04
    RESTful API 中的 Status code 是否要遵守规范
    RESTful API定义及使用规范
    Google protocol buff使用
    linux shell 值coredump suid_dumpable和 gdb解析coredump文件
    linux shell 之流程控制 if if else while
    error while loading shared libraries: libXXXX.so: cannot open shared object file: No such file or directory
    Excel表格写入操作函数 C++
  • 原文地址:https://www.cnblogs.com/Lucasleiva/p/4375410.html
Copyright © 2011-2022 走看看