📄 all.aspx
字号:
<%@ Page Language="C#" %>
<html>
<head>
<script language="javascript">
function ccClientValidate(source, arguments)
{
// 基于ANSI X4.13的信用卡验证规则,验证信用卡号是否有效
var cc = arguments.Value;
var ccSansSpace;
var i, digits, total;
// 取得信用卡号,并且确保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));
//将所有的偶数位加倍,并保证不超过10。 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];
// 如果结果能被10整除,就通过验证
if( total % 10 == 0 ) {
arguments.IsValid = true;
return;
}
else {
arguments.IsValid = false;
return;
}
}
</script>
</head>
<body>
<h3>客户注册</h3>
<hr>
<form method=post runat=server>
<asp:ValidationSummary ID="valSum" runat="server"
HeaderText="下面的字段输入有误:"
DisplayMode="SingleParagraph"
/><p>
Email地址:
<asp:TextBox id=email runat=server />
<%--必须验证控件,验证email输入框是否为空--%>
<asp:RequiredFieldValidator id="emailReqVal"
ControlToValidate="email"
ErrorMessage="Email."
Display="Dynamic"
runat=server>
*
</asp:RequiredFieldValidator>
<%--正则表达式验证控件,验证email是否符合格式--%>
<asp:RegularExpressionValidator id="emailRegexVal"
ControlToValidate="email"
ErrorMessage="Email. "
Display="Static"
ValidationExpression="^[\w]+([\w]|[\.]|[_])+[\w+]+@[\w+]+\.(com|net|org|edu)$"
runat=server>
输入的Email不符合格式,email格式如下email@host.domain。
</asp:RegularExpressionValidator><p>
密码:
<asp:TextBox id=passwd TextMode="Password" runat=server/>
<%--必须验证控件,验密码输入框是否为空--%>
<asp:RequiredFieldValidator id="passwdReqVal"
ControlToValidate="passwd"
ErrorMessage="密码. "
Display="Dynamic"
runat=server>
*
</asp:RequiredFieldValidator>
<%--正则表达式验证控件,验证密码是否符合格式--%>
<asp:RegularExpressionValidator id="passwdRegexBal"
ControlToValidate="passwd"
ErrorMessage="密码. "
ValidationExpression=".*[!@#$%^&*+;:].*"
Display="Static"
Width="12001%" runat=server>
密码必须包含下面的字符 (!@#$%^&*+;:)
</asp:RegularExpressionValidator>
再次输入密码:
<asp:TextBox id=passwd2 TextMode="Password" runat=server/>
<%--必须验证控件,验证密码输入框是否为空--%>
<asp:RequiredFieldValidator id="passwd2ReqVal"
ControlToValidate="passwd2"
ErrorMessage="确认密码. "
Display="Dynamic"
runat=server>
*
</asp:RequiredFieldValidator>
<%--比较验证控件,验证两次输入的密码是否相同--%>
<asp:CompareValidator id="CompareValidator1"
ControlToValidate="passwd2" ControlToCompare="passwd"
ErrorMessage="确认密码. "
Display="Static"
runat=server>
两次输入的密码不相同
</asp:CompareValidator><p>
<hr>
选择使用的信用卡:<p>
<ASP:RadioButtonList id=ccType RepeatLayout="Flow" runat=server>
<asp:ListItem>万事达卡</asp:ListItem>
<asp:ListItem>Visa卡</asp:ListItem>
</ASP:RadioButtonList>
<%--必须验证控件,验证用户是否已经选了信用卡类型--%>
<asp:RequiredFieldValidator id="ccTypeReqVal"
ControlToValidate="ccType"
ErrorMessage="信用卡类型. "
Display="Static"
InitialValue=""
runat=server>
*
</asp:RequiredFieldValidator><p>
信用卡号:
<ASP:TextBox id="ccNum" runat=server />
<%--必须验证控件,验证信用卡号输入框是否为空--%>
<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="ccClientValidate"
Display="Static"
Font-Name="Arial" Font-Size="11"
runat=server>
信用卡号无效,16位数字
</asp:CustomValidator><p>
信用卡有效期:
<ASP:DropDownList id=expDate runat=server>
<asp:ListItem></asp:ListItem>
<asp:ListItem >06/2001</asp:ListItem>
<asp:ListItem >07/2001</asp:ListItem>
<asp:ListItem >08/2001</asp:ListItem>
<asp:ListItem >09/2001</asp:ListItem>
<asp:ListItem >10/2001</asp:ListItem>
<asp:ListItem >11/2001</asp:ListItem>
<asp:ListItem >01/2002</asp:ListItem>
<asp:ListItem >02/2002</asp:ListItem>
<asp:ListItem >03/2002</asp:ListItem>
<asp:ListItem >04/2002</asp:ListItem>
<asp:ListItem >05/2002</asp:ListItem>
<asp:ListItem >06/2002</asp:ListItem>
<asp:ListItem >07/2002</asp:ListItem>
<asp:ListItem >08/2002</asp:ListItem>
<asp:ListItem >09/2002</asp:ListItem>
<asp:ListItem >10/2002</asp:ListItem>
<asp:ListItem >11/2002</asp:ListItem>
<asp:ListItem >12/2002</asp:ListItem>
</ASP:DropDownList>
<%--必须验证控件,验证用户是否选择了信用卡期限--%>
<asp:RequiredFieldValidator id="expDateReqVal"
ControlToValidate="expDate"
ErrorMessage="信用卡有效期. "
Display="Static"
InitialValue=""
runat=server>
*
</asp:RequiredFieldValidator><p>
<input runat="server" type=submit value="注册">
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -