1,用户名不能包含空格,第一个字母不能为数字,长度控制
2,密码和验证码要相同,不能为空,等等,一些很基本的功能,但是确实挺烦人的。
javascript调试起来确实比较麻烦。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language = "javascript">
function ger_code(code_length) {
var rand_aa="";
var code=new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J",
"K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h",
"i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","!","@","#","$","%","&",
"*","(",")","-","_","|","?","/");
var code_Num=code.length; //数组长度
for(i=0;i<code_length;i++)
{
var ran_ss=parseInt(Math.random()*code_Num);
rand_aa+=String(code[ran_ss]);
}
document.write(" 验证码 <input type=text name=check_code size="+code_length+" value="+rand_aa+" class=blank_bg maxsize=5 readonly=true>");
}
function subTest(){
var name = document.testForm.userName.value;
var pass = document.testForm.userPassword.value;
var rePass = document.testForm.reUserPassword.value;
var check = document.testForm.checkCode;
if(name.length > 10 || name.length < 4){
alert("用户名长度必须大于等于4,小于等于10");
testForm.userName.focus();
return false;
}else if(isFirst()){
alert("用户名头字母不能为数字");
testForm.userName.focus();
return false;
}else if(isSpace()){
alert("用户名只能包含字母,数字,下划线'_',以及'-'!");
testForm.userName.focus();
return false;
}
else if(pass.length < 1){
alert("请输入密码");
testForm.userPassword.focus();
return false;
}else if(pass != rePass){
alert("两次密码输入不相符合!");
testForm.reUserPassword.focus();
return false;
}
else if(check.value != testForm.check_code.value){
alert("验证码不正确");
testForm.checkCode.focus();
return false;
}
return true;
}
function isSpace(){
var name = document.testForm.userName.value.split("");
for(i = 0; i < name.length; i++){
if(name[i] == " "){
return true;
}else if( !((name[i] < "z" && name[i] > "a") || (name[i] < "Z" && name[i] > "A")
|| name[i] == "-" || name[i] == "_" || (name[i] < "9" && name[i] > "0"))){
return true;
}
}
return false;
}
function isFirst(){
var name = document.testForm.userName.value.split("");
if(name[0] < "9" && name[0] > "0"){
return true;
}
return false;
}
</script>
<style type=text/css>
.blank_bg {
background-color:#CC0000;
color:#FFFF00;
border-width:0px;
}
</style>
</HEAD>
<BODY>
<FORM action = "my2.htm" name = "testForm" method = "post" onSubmit="return subTest()">
<TABLE align = "center">
<TR>
<TD>用户名</TD>
<TD><INPUT TYPE="textarea" name = "userName" size = "10" ></TD>
<TD><font size = "5" color = "red">*</font>长度大于4,小于10</TD>
</TR>
<TR>
<TD>密码</TD>
<TD><INPUT type = "password" name = "userPassword"></TD>
<TD><font size = "5" color = "red">*</font>必填</TD>
</TR>
<TR>
<TD>验证密码</TD>
<TD><INPUT type = "password" name = "reUserPassword"></TD>
<TD><font size = "5" color = "red">*</font>必填</TD>
</TR>
<TR>
<TD>验证码</TD>
<TD><INPUT type = "textarea" name = "checkCode"></TD>
<TD><SCRIPT language = "JavaScript">ger_code(5);</SCRIPT><font size = "5" color = "red">*</font>必填</TD>
<TD></TD>
</TR>
<TR>
<TD><DIV ALIGN = "CENTER"><INPUT TYPE = "submit", VALUE = "登陆" ></DIV></TD>
<TD><DIV ALIGN = "CENTRE"><INPUT TYPE = "reset" ></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
posted on 2006-09-14 23:48
JavaCoffe 阅读(7748)
评论(0) 编辑 收藏 所属分类:
J2EE 学习