<%@ Page language="c#" Codebehind="Validator.aspx.cs" AutoEventWireup="false" Inherits="RegistWeb.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>WebForm1</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
	</HEAD>
	<body>
		<center>
			<h3><font face="宋体"> 验证用户注册页面示例</font></h3>
			<form method="post" runat="server" ID="Form1">
				<asp:ValidationSummary ID="valSum" runat="server" HeaderText="必须在下列字段中输入有效的值:" DisplayMode="SingleParagraph" Font-Name="verdana" Font-Size="12" />
				<p>
					<!-- sign-in -->
					<table border="0" width="600">
						<tr>
							<td colspan="3" style="HEIGHT: 20px"><FONT face="宋体,geneva,arial" size="-1"><B>登录信息</B></FONT>
							</td>
						</tr>
						<tr>
							<td align="right" style="WIDTH: 68px">
								<P>
									<font face="宋体" size="2">电子邮件 &nbsp;</font><FONT face="宋体" size="2">地址：</FONT>
								</P>
							</td>
							<td>
								<asp:TextBox id="email" width="200px" maxlength="60" runat="server" />
							</td>
							<td>
								<asp:RequiredFieldValidator id="emailReqVal" ControlToValidate="email" ErrorMessage="电子邮件。" Display="Dynamic" Font-Name="Verdana" Font-Size="12" runat="server">
            *
        </asp:RequiredFieldValidator>
								<asp:RegularExpressionValidator id="emailRegexVal" ControlToValidate="email" ErrorMessage="电子邮件。" Display="Static" ValidationExpression="^[\w-]+@[\w-]+\.(com|net|org|edu|mil)$" Font-Name="Arial" Font-Size="11" runat="server">
            不是有效的电子邮件地址。必须遵循此格式：email@host.domain。
        </asp:RegularExpressionValidator>
							</td>
						</tr>
						<tr>
							<td align="right" style="WIDTH: 68px">
								<font face="宋体" size="2">密码：</font>
							</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="Verdana" Font-Size="12" runat="server">
              *
          </asp:RequiredFieldValidator>
								<asp:RegularExpressionValidator id="passwdRegexBal" ControlToValidate="passwd" ErrorMessage="密码。" ValidationExpression=".*[!@#$%^&amp;*+;:].*" Display="Static" Font-Name="Arial" Font-Size="11" Width="100%" runat="server">
              密码必须包含下列字符之一：  (!@#$%^&amp;*+;:)
          </asp:RegularExpressionValidator>
							</td>
						</tr>
						<tr>
							<td align="right" style="WIDTH: 68px">
								<font face="宋体" size="2">确认密码：</font>
							</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="Verdana" Font-Size="12" runat="server">
            *
        </asp:RequiredFieldValidator>
								<asp:CompareValidator id="CompareValidator1" ControlToValidate="passwd2" ControlToCompare="passwd" ErrorMessage="重新输入密码。" Display="Static" Font-Name="Arial" Font-Size="11" runat="server">
            密码字段不匹配
        </asp:CompareValidator>
							</td>
						</tr>
						<!-- personalization information -->
						<tr>
							<td colspan="3"><FONT face="宋体,geneva,arial" size="-1"><B>个人信息</B></FONT>
							</td>
						</tr>
						<tr>
							<td align="right" style="WIDTH: 68px">
								<font face="宋体" size="2">名字：</font>
							</td>
							<td>
								<asp:TextBox id="fn" maxlength="20" width="200px" runat="server" />
							</td>
							<td>
							</td>
						</tr>
						<tr>
							<td align="right" style="WIDTH: 68px">
								<font face="宋体" size="2">姓氏：</font>
							</td>
							<td>
								<asp:TextBox id="ln" maxlength="40" width="200px" runat="server" />
							</td>
							<td>
							</td>
						</tr>
						<tr>
							<td align="right" style="WIDTH: 68px">
								<font face="宋体" size="2">地址：</font>
							</td>
							<td>
								<asp:TextBox id="address" width="200px" runat="server" />
							</td>
							<td>
							</td>
						</tr>
						<tr>
							<td align="right" style="WIDTH: 68px">
								<font face="宋体" size="2">州:</font>
							</td>
							<td>
								<asp:TextBox id="state" width="30px" maxlength="2" runat="server" />&nbsp; <font face="宋体" size="2">
									邮政编码：</font>&nbsp;
								<ASP:TextBox id="zip" width="60px" maxlength="5" runat="server" />
							</td>
							<td>
								<asp:RegularExpressionValidator id="RegularExpressionValidator1" ControlToValidate="zip" ErrorMessage="邮政编码。" ValidationExpression="^\d{6}$" Display="Static" Font-Name="Arial" Font-Size="11" runat="server">
            邮政编码必须是 6 位数字
        </asp:RegularExpressionValidator>
							</td>
						</tr>
						<tr>
							<td align="right" style="WIDTH: 68px">
								<font face="宋体" size="2">电话：</font>
							</td>
							<td>
								<asp:TextBox id="phone" maxlength="20" runat="server" />
							</td>
							<td>
								<asp:RequiredFieldValidator id="phoneReqVal" ControlToValidate="phone" ErrorMessage="电话。" Display="Dynamic" Font-Name="Verdana" Font-Size="12" runat="server">
            *
        </asp:RequiredFieldValidator>
								<asp:RegularExpressionValidator id="phoneRegexVal" ControlToValidate="phone" ErrorMessage="电话。" ValidationExpression="(^x\s*[0-9]{5}$)|(^(\([1-9][0-9]{2}\)\s)?[1-9][0-9]{2}-[0-9]{4}(\sx\s*[0-9]{5})?$)" Display="Static" Font-Name="Arial" Font-Size="11" runat="server">
            必须为此格式：(XXX) XXX-XXXX
        </asp:RegularExpressionValidator>
							</td>
						</tr>
						<!-- Credit Card Info -->
						<tr>
							<td colspan="3">
								<font face="宋体" size="2"><b>信用卡信息</b></font>
							</td>
						</tr>
						<tr>
							<td align="right" style="WIDTH: 68px">
								<font face="宋体" size="2">卡类型:</font>
							</td>
							<td>
								<ASP:RadioButtonList id="ccType" Font-Name="Arial" RepeatLayout="Flow" runat="server">
									<asp:ListItem>MasterCard</asp:ListItem>
									<asp:ListItem>Visa</asp:ListItem>
								</ASP:RadioButtonList>
							</td>
							<td>
								<asp:RequiredFieldValidator id="ccTypeReqVal" ControlToValidate="ccType" ErrorMessage="卡类型。" Display="Static" InitialValue="" Font-Name="Verdana" Font-Size="12" runat="server">
            *
        </asp:RequiredFieldValidator>
							</td>
						</tr>
						<tr>
							<td align="right" style="WIDTH: 68px">
								<font face="宋体" size="2">卡号：</font>
							</td>
							<td>
								<ASP:TextBox id="ccNum" runat="server" />
							</td>
							<td>
								<asp:RequiredFieldValidator id="ccNumReqVal" ControlToValidate="ccNum" ErrorMessage="卡号。" Display="Dynamic" Font-Name="Verdana" Font-Size="12" runat="server">
            *
        </asp:RequiredFieldValidator>
								<asp:CustomValidator id="ccNumCustVal" ControlToValidate="ccNum" ErrorMessage="卡号。" clientvalidationfunction="ClientValidate" Display="Static" Font-Name="Arial" Font-Size="11" runat="server">
            不是有效的信用卡号。必须包含 16 位数字。
        </asp:CustomValidator>
							</td>
						</tr>
						<tr>
							<td align="right" style="WIDTH: 68px">
								<font face="宋体" size="2">到期日期：</font>
							</td>
							<td>
								<ASP:DropDownList id="expDate" runat="server">
									<asp:ListItem></asp:ListItem>
									<asp:ListItem>01/01</asp:ListItem>
									<asp:ListItem>02/01</asp:ListItem>
									<asp:ListItem>03/01</asp:ListItem>
									<asp:ListItem>04/01</asp:ListItem>
									<asp:ListItem>05/01</asp:ListItem>
									<asp:ListItem>06/01</asp:ListItem>
									<asp:ListItem>07/01</asp:ListItem>
									<asp:ListItem>08/01</asp:ListItem>
									<asp:ListItem>09/01</asp:ListItem>
									<asp:ListItem>10/01</asp:ListItem>
									<asp:ListItem>11/01</asp:ListItem>
									<asp:ListItem>12/01</asp:ListItem>
								</ASP:DropDownList>
							</td>
							<td>
								<asp:RequiredFieldValidator id="expDateReqVal" ControlToValidate="expDate" ErrorMessage="到期日期。" Display="Static" InitialValue="" Font-Name="Verdana" Font-Size="12" runat="server">
          *
        </asp:RequiredFieldValidator>
							</td>
						</tr>
					</table>
				</p>
				<p>
					<input runat="server" type="submit" value="提交" ID="Submit1" NAME="Submit1"></p>
				<p><FONT face="宋体"></FONT></p>
				<script language="javascript">

        function ClientValidate(source, arguments)
        {
            var cc = arguments.Value;
            var ccSansSpace;
            var i, digits, total;

            // 只是示例。不是实际的信用卡算法。
            // 基于 ANSI X4.13，使用 LUHN 规则（也称为模 10 算法）
            // 执行生成和/或验证，并验证一些信用卡号的正确性。

            // 获取数字，去除所有的非数字字符，应剩余 16 位数字
            ccSansSpace = cc.replace(/\D/g, "");
            if(ccSansSpace.length != 16) {
                arguments.IsValid = false;
                return;   // 无效的信用卡号
            }

            // 转换为数字数组
            digits = new Array(16);
            for(i=0; i<16; i++)
                digits[i] = Number(ccSansSpace.charAt(i));

            // 每隔一位，将数字加倍然后将数字相加
            for(i=0; i<16; i+=2) {
                digits[i] *= 2;
                if(digits[i] > 9)   digits[i] -= 9;
            }

            // 将数字相加
            total = 0;
            for(i=0; i<16; i++)     total += digits[i];

            // 结果
            if( total % 10 == 0 )   {
                arguments.IsValid = true;
                return;    // 有效的信用卡号
            }
            else  {
                arguments.IsValid = false;
                return;   // 无效的信用卡号
            }
        }

				</script>
			</form>
		</center>
	</body>
</HTML>
