web form 服务器控件表单验证
1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ValidationDemo.aspx.cs" Inherits="Validation.ValidationDemo" %> 2 3 <!DOCTYPE html> 4 5 <html xmlns="http://www.w3.org/1999/xhtml"> 6 <head runat="server"> 7 <title></title> 8 </head> 9 <body> 10 <form id="form1" runat="server"> 11 <div> 12 <table class="auto-style1"> 13 <tr> 14 <td>Name:</td> 15 <td> 16 <asp:TextBox ID="TextName" runat="server"></asp:TextBox> 17 <asp:RequiredFieldValidator ID="RequiredFieldValidator1" 18 runat="server" ControlToValidate="TextName" 19 ErrorMessage="Name required">*</asp:RequiredFieldValidator> 20 </td> 21 </tr> 22 <tr> 23 <td>Email:</td> 24 <td> 25 <asp:TextBox ID="TextEmail" runat="server"></asp:TextBox> 26 <asp:RequiredFieldValidator ID="RequiredFieldValidator2" 27 runat="server" ControlToValidate="TextEmail" Display="Dynamic" 28 ErrorMessage="Email required">*</asp:RequiredFieldValidator> 29 <asp:RegularExpressionValidator ID="RegularExpressionValidator1" 30 runat="server" ControlToValidate="TextEmail" Display="Dynamic" 31 ErrorMessage="Please enter an email" 32 ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator> 33 </td> 34 </tr> 35 <tr> 36 <td> 37 <asp:Button ID="Button1" runat="server" Text="Register" /> 38 </td> 39 <td> </td> 40 </tr> 41 </table> 42 43 </div> 44 <asp:ValidationSummary ID="ValidationSummary1" runat="server" /> 45 </form> 46 </body> 47 </html>
鹰击长空,鱼翔浅底