日期:2009-11-25 浏览次数:20535 次
<HTML>
<script language="JavaScript">
function ClientValidateEmail(source, value)
{
var strr;
re=/(\w+@\w+\.\w+)(\.{0,1}\w*)(\.{0,1}\w*)/i;
re.exec(value);
if (RegExp.$3!=""&&RegExp.$3!="."&&RegExp.$2!=".") strr=RegExp.$1+RegExp.$2+RegExp.$3
else
if (RegExp.$2!=""&&RegExp.$2!=".") strr=RegExp.$1+RegExp.$2
else strr=RegExp.$1
if (strr!=value)
return false;
else
return true;
}
</script>
<body>
<h3>ASP.NET验证用户输入</h3>
<form method=post runat=server>
<hr width=600 size=1 noshade>
<table>
<tr>
<td>
<ASP:ValidationSummary ID="valSum" runat="server"
HeaderText="你必须输入下面这些表单域:"
DisplayMode="bulletlist"
Font-Name="宋体"
Font-Size="12"
/>
</td>
</tr>
</table>
<center>
<p>
<!-- 登陆信息 -->
<table border=0 width=600 >
<tr><td colspan=3>
<table border=0 cellpadding=0 cellspacing=0 width="100%">
<tr><td>
<b>登陆信息</b>
</td></tr>
</table>
</td></tr>
<tr>
<td align=right>
Email地址:
</td>
<td>
<ASP:TextBox id=email width=200px maxlength=60 runat=server />
</td>
<td>
<ASP:RequiredFieldValidator id="emailReqVal"
ControlToValidate="email"
ErrorMessage="Email地址"
Display="Dynamic"
Font-Name="宋体"
Font-Size="12"
runat=server>
*
</ASP:RequiredFieldValidator>
<ASP:CustomValidator id="emailRegexVal" runat="server"
ControlToValidate="email"
ClientValidationFunction="ClientValidateEmail"
Display="Static"
Font-Name="宋体"
Font-Size="12">
非法Email地址
</ASP:CustomValidator>
</td>
</tr>
<tr>
<td align=right>
密码:
</td>
<td>
<ASP:TextBox id=passwd TextMode="Password" maxlength=20 runat=server/>
</td>
<td>
<ASP:RequiredFieldValidator id="passwdReqVal"
ControlToValidate="passwd"
ErrorMessage="用户密码"
Display="Dynamic"
Font-Name="宋体" Font-Size="12"
runat=server>
*
</ASP:RequiredFieldValidator>
<ASP:RegularExpressionValidator id="passwdRegexBal"
ControlToValidate="passwd"
ValidationExpression=".*[!@#$%^&*+;:].*"
Display="Static"
Font-Name="宋体" Font-Size="12"
Width="100%" runat=server>
密码必须包含如下字符: (!@#$%^&*+;:)
</ASP:RegularExpressionValidator>
</td>
</tr>
<tr>
<td align=right>
确认密码
</td>
<td>
<ASP:TextBox id=passwd2 TextMode="Password" maxlength=20 runat=server/>
</td>
<td>
<ASP:RequiredFieldValidator id="passwd2ReqVal"
ControlToValidate="passwd2"
ErrorMessage="确认密码"
Display="Dynamic"
Font-Name="宋体" Font-Size="12"
runat=server>
*
</ASP:RequiredFieldValidator>
<ASP:CompareValidator id="CompareValidator1"
ControlToValidate="passwd2" ControlToCompare="passwd"
Display="Static"
Font-Name="宋体" Font-Size="12"
runat=server>
密码不符合
</ASP:CompareValidator>
</td>
</tr>
<tr><td colspan=3> </td></tr>
<!-- 私人信息 -->
<tr><td colspan=3>
<table border=0 cellpadding=0 cellspacing=0 width="100%">
<tr><td>
<b>个人信息</b>
</td></tr>
</table>
</td></tr>
<tr>
<td align=right>
姓名:
</td>
<td>
<ASP:TextBox id=pname maxlength=20 width=200px runat=