How to use the ‘RegularExpressionValidator‘ and ‘RequiredFieldValidator‘ in ASP.NET:
I have used these to validate an email address. see the code below:
< asp:TextBox runat="server" ID="Email" Columns="30">
< asp:RequiredFieldValidator ID="EmailValidator" runat="server"
ControlToValidate="Email" display="Dynamic"
ErrorMessage="Email must be filled out" />
< asp:RegularExpressionValidator ID="EmailValidator2" runat="server"
ControlToValidate="ToEmail" Display="Dynamic"
ErrorMessage="This is not a valid email address"
ValidationExpression="^[a-zA-Z][w.-]*[a-zA-Z0-9]@
[a-zA-Z0-9][w.-]*[a-zA-Z0-9].[a-zA-Z][a-zA-Z.]*[a-zA-Z]$" />
Also, use the CompareValidator to confirm the entered email;
< asp:CompareValidator ID="Comparevalidator2" Runat="server"
ControlToCompare="ReplyToEmail" ControlToValidate="contactEmailAddVerify"
Display="Dynamic" ErrorMessage="The Entered Email Confirmation does not match."
Font-Size="8" Operator="Equal" style="font-size: x-small">