- First Name
- Last Name
- Email Address
- <form id="simpleForm" runat="server">
- <div>
- First Name:<asp:TextBox ID="txtFName" runat="server"></asp:TextBox>
- <br />
- Last Name:<asp:TextBox ID="txtLName" runat="server"></asp:TextBox>
- <br />
- Email Address:<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
- <br />
- </div>
- </form>
After we add our validation controls, which you can add from the "Validation" tab of the Toolbox, the code looks like this:
- <form id="signUp" runat="server">
- <div style="width: 957px">
- First Name:<asp:TextBox ID="txtFName" runat="server"></asp:TextBox>
- <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
- ControlToValidate="txtFName" ErrorMessage="First Name Required"></asp:RequiredFieldValidator>
- <br />
- Last Name:<asp:TextBox ID="txtLName" runat="server"></asp:TextBox>
- <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
- ControlToValidate="txtLName" ErrorMessage="Last Name Required"></asp:RequiredFieldValidator>
- <br />
- Email Address:<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
- <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
- ControlToValidate="txtEmail" ErrorMessage="Enter a vaild email address"
- ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
- <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
- ControlToValidate="txtEmail" ErrorMessage="Email address required"></asp:RequiredFieldValidator>
- <br />
- </div>
- </form>
And what will happen now is our web form will make the First Name, Last Name and email fields required, as well as validate that the email address is really an email address.