<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>注册表单验证</title>
</head>
<body style="background-image: url(0267.jpg)">
<h4>注册表单验证实例</h4>
<hr />
<form id="form1" runat="server">
<div>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="right" >注册账号:
</td>
<td colspan="2" style=" color: red; ">
<asp:TextBox ID="TextBox1" runat="server" Width="381px"></asp:TextBox>
*<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="注册账号不能为空"
ControlToValidate="TextBox1" EnableTheming="True" Display="None" EnableViewState="False"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="必须是数字和字母" ValidationExpression="^[A-Za-z0-9]+$" Display="None"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td align="right" >
密码:
</td>
<td colspan="2" style=" color: red; ">
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password" Width="381px"></asp:TextBox>
*<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2"
ErrorMessage="密码不能为空" Display="None"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TextBox2"
ControlToValidate="TextBox3" ErrorMessage="密码和重复密码必须相同" Display="None"></asp:CompareValidator></td>
</tr>
<tr>
<td align="right" >重复密码:
</td>
<td colspan="2" style=" color: red; ">
<asp:TextBox ID="TextBox3" runat="server" TextMode="Password" Width="381px"></asp:TextBox>
*<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox3"
ErrorMessage="重复密码不能为空" Display="None"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td align="right" style="width: 100px">
姓名:
</td>
<td colspan="2" style=" color: red; ">
<asp:TextBox ID="TextBox4" runat="server" Width="381px"></asp:TextBox>
*<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TextBox4"
ErrorMessage="姓名必须填写" Display="None"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td align="right" >
年龄:
</td>
<td colspan="2" >
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="年龄超出范围(15-110),请正确输入"
MaximumValue="110" MinimumValue="15" ControlToValidate="TextBox5" Type="Integer" Display="None"></asp:RangeValidator></td>
</tr>
<tr>
<td align="right" >
保密邮箱:
</td>
<td style="color: #ff0033">
<asp:TextBox ID="TextBox6" runat="server" Width="260px"></asp:TextBox>
*<asp:RegularExpressionValidator
ID="RegularExpressionValidator2" runat="server" ErrorMessage="请正确输入邮箱" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="TextBox6" Display="None"></asp:RegularExpressionValidator></td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Button ID="Button1" runat="server" Text="提交" Width="75px" OnClick="Button1_Click" CssClass="Button" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:ValidationSummary id="ValidationSummary1" runat="server" HeaderText="错误信息"></asp:ValidationSummary>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>