JS注册客户端验证

 1 function checklogin(){
2 if (document.form2.username.value==0) {document.getElementById("userdiv").innerHTML="<img src='images/error.gif' align='absmiddle' />请输入用户名";document.getElementById("userdiv").className="yangshi";return false;}
3 else {
4
5 if (document.form2.username.value.length>=10)
6
7 {document.getElementById("userdiv").innerHTML="<img src='images/error.gif' align='absmiddle' />用户名长度不能超过10个字符";
8
9 document.getElementById("userdiv").className="yangshi";
10
11 return false;}
12 else {document.getElementById("userdiv").innerHTML="<img src='images/right.gif' />";document.getElementById("userdiv").className="yangshir";}
13 }
14
15 if (document.form2.mm.value==0) {document.getElementById("pw").innerHTML="<img src='images/error.gif' align='absmiddle' /><font color=red>请输入密码</font>";return false;}
16 else {document.getElementById("pw").innerHTML="<img src='images/right.gif' />";}
17
18 if (document.form2.mm.value.length>18) {document.getElementById("pw").innerHTML="<img src='images/error.gif' align='absmiddle' /><font color=red>密码长度不能超过18位</font>";return false;}
19 else {document.getElementById("pw").innerHTML="<img src='images/right.gif' />";}
20
21
22 //密码重复
23
24 if (document.form2.mm2.value!=document.form2.mm.value) {document.getElementById("repw").innerHTML="<img src='images/error.gif' align='absmiddle' /><font color='red'>重复的密码不正确</font>";return false;}
25 else {document.getElementById("repw").innerHTML="<img src='images/right.gif' />";}
26
27
28
29 if (document.form2.tel.value==0) {document.getElementById("teldiv").innerHTML="<img src='images/error.gif' align='absmiddle' />请输入你的电话,以便和你联系";document.getElementById("teldiv").className="yangshi";return false;}
30 else {document.getElementById("teldiv").innerHTML="<img src='images/right.gif' />";document.getElementById("teldiv").className="yangshir";}
31
32
33
34 if (document.form2.qq.value==0) {document.getElementById("qqdiv").innerHTML="<img src='images/error.gif' align='absmiddle' />请输入你的QQ,以便和你联系";document.getElementById("qqdiv").className="yangshi";return false;}
35 else {document.getElementById("qqdiv").innerHTML="<img src='images/right.gif' />";document.getElementById("qqdiv").className="yangshir";}
36
37
38
39 if (document.form2.msn.value==0)
40 {document.getElementById("msndiv").innerHTML="<img src='images/error.gif' align='absmiddle' />请输入你的MSN,如果没有可随便填写!";
41 document.getElementById("msndiv").className="yangshi";
42 return false;}
43 else
44 {document.getElementById("msndiv").innerHTML="<img src='images/right.gif' />";
45 document.getElementById("msndiv").className="yangshir";}
46
47
48
49 if (0 == document.form2.email.value.length) {
50 document.getElementById("emaildiv").className="yangshi";
51 document.getElementById("emaildiv").innerHTML="<img src='images/error.gif' align='absmiddle' />请输入您的邮箱地址!";
52 return false;
53 }
54 else
55 {
56 document.getElementById("emaildiv").className="yangshir";
57 document.getElementById("emaildiv").innerHTML="<img src='images/right.gif' />";
58 }
59
60 var email = document.form2.email.value
61 var is_error = false
62 var pn_0 = email.indexOf("@")
63 var pn_1 = email.indexOf(".",pn_0)
64 var pn_2 = email.length
65 if (pn_0<1 || pn_1<pn_0+2 || pn_1+2>pn_2) is_error=true
66 if (is_error) {
67 document.getElementById("emaildiv").className="yangshi";
68 document.getElementById("emaildiv").innerHTML="<img src='images/error.gif' align='absmiddle' />请输入正确的邮件格式";
69 return false;
70 }
71 else
72 {
73 document.getElementById("emaildiv").className="yangshir";
74 document.getElementById("emaildiv").innerHTML="<img src='images/right.gif' />";
75 }
76
77
78
79 if (document.form2.answer.value==0) {document.getElementById("answerdiv").innerHTML="<img src='images/error.gif' align='absmiddle' />请输入密码提示答案";document.getElementById("answerdiv").className="yangshi";return false;}
80 else {document.getElementById("answerdiv").innerHTML="<img src='images/right.gif' />";document.getElementById("answerdiv").className="yangshir";}
81 }
82
83
84 </script>

 

posted on 2012-03-26 15:00  zhangtao1212  阅读(292)  评论(0编辑  收藏  举报

导航