日期:2014-05-16 浏览次数:20373 次
<TABLE> <form name="form1" id="form1"> <TR> <TD>用户名:</TD> <TD><INPUT TYPE="text" NAME="user"></TD> <TD rowspan="3" id="msg" style="color:red" valign="top"></TD> </TR> <TR> <TD>密码:</TD> <TD><INPUT TYPE="password" NAME="psw"></TD> </TR> <TR> <TD colspan="2" align="center"><INPUT TYPE="button" value="登录" onclick="check()"></TD> </TR> </form> </TABLE> <SCRIPT LANGUAGE="JavaScript"> <!-- function check(){ var len = 6; var form1 = document.getElementById("form1"); var msg = document.getElementById("msg"); var reg = /^[0-9a-zA-Z_]+$/ if (form1.user.value=="") msg.innerHTML = "请填写用户名"; else if (form1.psw.value=="") msg.innerHTML = "请填写密码"; else if (form1.psw.value.length< len) msg.innerHTML = "密码至少为6位"; else if (!reg.test(form1.user.value)) msg.innerHTML = "用户名只能由数字、字母或下划线组成"; else if (!reg.test(form1.psw.value)) msg.innerHTML = "密码只能由数字、字母或下划线组成"; else alert("pass!") } //--> </SCRIPT>