一 问题描述
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>
时间: 2024-10-14 06:31:27