日期:2014-05-16  浏览次数:20643 次

Javascript验证输入信息
function CheckData()
2     {
3         if(document.addAdminForm.txtAccount.value == "")
4         {
5             alert("用户名不能为空!");
6             return false;
7         }
8         if(document.addAdminForm.txtPass1.value == "")
9         {
10             alert("密码不能为空!");
11             return false;
12         }
13         if(document.addAdminForm.txtPass2.value == "")
14         {
15             alert("密码确认不能为空!");
16             return false;
17         }
18         if(document.addAdminForm.txtPass1.value != document.addAdminForm.txtPass2.value)
19         {
20             alert("两次密码输入不一致");
21             return false;
22         }
23        
24         //检查邮箱地址
25         if(document.addAdminForm.txtEmail.value != "")
26         {
27             var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
28             if(!reg.test(document.addAdminForm.txtEmail.value))
29             {
30                 alert("Email格式不正确!");
31                 return false;
32             }
33             return true;
34         }
35     }