c# asp.net 正则表达式(12)
body>
<form id="form1" runat="server">
<div style="text-align:center">
演示正则表达式控件
<hr style="width:50%" />
填写学生个人信息<br />
学生姓名:
<asp:TextBox ID="name" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="REValidator1" runat="server"
ErrorMessage="姓名格式不对" ControlToValidate="name"
ValidationExpression="\w{4,12}">*</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator runat="server" ID="RQfile" ControlToValidate="name" ErrorMessage="姓名不能为空">*</asp:RequiredFieldValidator><br />
出生日期:
<asp:TextBox ID="birth" runat="server" ></asp:TextBox>
<asp:RegularExpressionValidator runat="server" ID="REValidator2" ErrorMessage="日期格式不对" ControlToValidate="birth"
ValidationExpression="\d{4}([/-])+\d{1,2}([/-])+\d{1,2}">*</asp:RegularExpressionValidator><br />
联系电话:
<asp:TextBox runat="server" ID="tel"></asp:TextBox>
<asp:RegularExpressionValidator runat="server" ID="REValidator3" ErrorMessage="电话格式不对" ControlToValidate="tel"
ValidationExpression="\d{11}|(\d{3,4}-)?\d{7,8}">*</asp:RegularExpressionValidator> <br />
电子邮件:
<asp:TextBox runat="server" ID="email"></asp:TextBox>
<asp:RegularExpressionValidator ID="REValidator4" runat="server" ErrorMessage="电话格式不对" ControlToValidate="email"
ValidationExpression="\w+([+-.])*@\w+([-.]\w)*\.\w+([-.]\w)*">*</asp:RegularExpressionValidator><br />
<asp:Button runat="server" ID="Button1" Text="提交" OnClick="button_Click"/><br />
<asp:Label ID="Label1" runat="server" Width="353px" ForeColor="Red"></asp:Label>
</div>
</form>
</body>
protected void button_Click(object sender, EventArgs e)
{
//验证提示
if (Page.IsValid)
Label1.Text = "验证成功";
}
本文出自 “神舟龙” 博客,请务必保留此出处http://shenzhoulong.blog.51cto.com/1191789/304834