在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
ASP.NET中 RegularExpressValidator(正则验证)的使用。
RegularExpressionValidator:正则验证属性: ControlToValidate:要验证的控件 ErrorMessage:错误提示信息 ValidationExpression:正则表达式 1, 身份证号: 省份证号有误 2,邮编: 邮编有误 3,电话号码: 电话号码有误 4,电子邮箱: 电子邮箱有误 5,网站(URL):
/Demo3.aspx
View Code
<%@ 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>
https://files.cnblogs.com/ylbtech/WebForm-BasicControl-Validator.rar
|
请发表评论