1.A,运行效果返回顶部 |
RegularExpressionValidator:正则验证
属性:
ControlToValidate:要验证的控件
ErrorMessage:错误提示信息
ValidationExpression:正则表达式
1,
身份证号: 省份证号有误
2,邮编: 邮编有误
3,电话号码: 电话号码有误
4,电子邮箱: 电子邮箱有误
5,网站(URL): 网址有误
1.B,源代码返回顶部 |
/Demo3.aspx
![](https://i-blog.csdnimg.cn/blog_migrate/81178cc93a2a3bb5048d90d76e7ec935.gif)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Demo3.aspx.cs" Inherits="Demo3" %> <!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> <form id="form1" runat="server"> <div> <h2>RegularExpressionValidator:正则验证</h2> <hr /> 属性:<br /> ControlToValidate:要验证的控件<br /> ErrorMessage:错误提示信息<br /> ValidationExpression:正则表达式<br /> <hr /> <br /> 1,<br /> 身份证号:<asp:TextBox ID="txtID" runat="server"></asp:TextBox> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtID" ErrorMessage="省份证号有误" ValidationExpression="\d{17}[\d|X]|\d{15}"></asp:RegularExpressionValidator> <br /> <br /> 2,邮编:<asp:TextBox ID="txtZipCode" runat="server"></asp:TextBox> <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtZipCode" ErrorMessage="邮编有误" ValidationExpression="\d{6}"></asp:RegularExpressionValidator> <br /> <br /> 3,电话号码:<asp:TextBox ID="txtTel" runat="server"></asp:TextBox> <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="txtTel" ErrorMessage="电话号码有误" ValidationExpression="(\(\d{3}\)|\d{3}-)?\d{8}"></asp:RegularExpressionValidator> <br /> <br /> 4,电子邮箱:<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox> <asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="txtEmail" ErrorMessage="电子邮箱有误" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator> <br /> <br /> 5,网站(URL):<asp:TextBox ID="txtURL" runat="server"></asp:TextBox> <asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server" ControlToValidate="txtURL" ErrorMessage="网址有误" ValidationExpression="http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"></asp:RegularExpressionValidator> <br /> <br /> <br /> <asp:Button ID="Button1" runat="server" Text="提交" /> <br /> </div> </form> </body> </html>
1.C,资源下载返回顶部 |
http://files.cnblogs.com/ylbtech/WebForm-BasicControl-Validator.rar