当前位置:首页 > 网络编程 > WEB编程 > ASP.net > ASP.NET学习手记:验证用户表单输入

ASP.NET学习手记:验证用户表单输入

点击次数:24 次 发布日期:2008-11-26 23:17:33 作者:源代码网
源代码网推荐 运行环境:Win2000 Advance Server+IIS5.0+NGWS SDK(80M的).
源代码网推荐其中验证email地址的函数用的是廖兄精华区中的代码.
源代码网推荐<%@ Page Language="C#" %>

<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=server />
源代码网推荐</td>
源代码网推荐<td>
源代码网推荐</td>
源代码网推荐</tr>
源代码网推荐<tr>
源代码网推荐<td align=right>
源代码网推荐地址:
源代码网推荐</td>
源代码网推荐<td>
源代码网推荐<asp:TextBox id=address width=200px runat=server />
源代码网推荐</td>
源代码网推荐<td>
源代码网推荐</td>
源代码网推荐</tr>
源代码网推荐<tr>
源代码网推荐<td align=right>
源代码网推荐邮编:
源代码网推荐</td>
源代码网推荐<td>
源代码网推荐<ASP:TextBox id=postcode width=60px maxlength=6 runat=server />
源代码网推荐</td>
源代码网推荐<td>
源代码网推荐<asp:RegularExpressionValidator id="RegularExpressionValidator1"
源代码网推荐ControlToValidate="postcode"
源代码网推荐ValidationExpression="^d{6}$"
源代码网推荐Display="Static"
源代码网推荐Font-Name="宋体" Font-Size="12"
源代码网推荐runat=server>
源代码网推荐邮编必须是6位数字
源代码网推荐</asp:RegularExpressionValidator>
源代码网推荐</td>
源代码网推荐</tr>
源代码网推荐<tr>
源代码网推荐<td align=right>
源代码网推荐性别:
源代码网推荐</td>
源代码网推荐<td>
源代码网推荐<ASP:RadioButtonList id=sexType runat=server>
源代码网推荐<asp:ListItem>男</asp:ListItem>
源代码网推荐<asp:ListItem>女</asp:ListItem>
源代码网推荐</ASP:RadioButtonList>
源代码网推荐</td>
源代码网推荐<td>
源代码网推荐<asp:RequiredFieldValidator id="sexTypeReqVal"
源代码网推荐ControlToValidate="sexType"
源代码网推荐ErrorMessage="性别"
源代码网推荐Display="Static"
源代码网推荐InitialValue=""
源代码网推荐Font-Name="宋体" Font-Size="12"
源代码网推荐runat=server>
源代码网推荐*
源代码网推荐</asp:RequiredFieldValidator>
源代码网推荐</td>
源代码网推荐</tr>
源代码网推荐<tr>
源代码网推荐<td align=right>
源代码网推荐出生年份:
源代码网推荐</td>
源代码网推荐<td>
源代码网推荐<ASP:DropDownList id=expYear runat=server>
源代码网推荐<asp:ListItem></asp:ListItem>
源代码网推荐<asp:ListItem >1976</asp:ListItem>
源代码网推荐<asp:ListItem >1975</asp:ListItem>
源代码网推荐</ASP:DropDownList>
源代码网推荐</td>
源代码网推荐<td>
源代码网推荐<asp:RequiredFieldValidator id="expDateReqVal"
源代码网推荐ControlToValidate="expYear"
源代码网推荐ErrorMessage="出生年份"
源代码网推荐Display="Static"
源代码网推荐InitialValue=""
源代码网推荐Font-Name="宋体" Font-Size="12"
源代码网推荐runat=server>
源代码网推荐*
源代码网推荐</asp:RequiredFieldValidator>
源代码网推荐</td>
源代码网推荐</tr>
源代码网推荐</table>
源代码网推荐
源代码网推荐<p>
源代码网推荐<input runat="server" type=submit value="提 交">
源代码网推荐<p>
源代码网推荐</form>
源代码网推荐</center>
源代码网推荐</body>
源代码网推荐</html>
源代码网推荐


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华