有效等价类和无效等价类:
有效等价类 | 无效等价类 |
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 | 有效 |