<td colspan="3" style="text-align: left">
<asp:TextBox ID="txtEmailAddress" runat="server" Width="241px" MaxLength="100"></asp:TextBox>
<asp:requiredfieldvalidator id="RequiredFieldValidator3"
controltovalidate="txtEmailAddress"
errormessage="Email Address."
text=" *" runat="server"
SetFocusOnError="True" />
<asp:CustomValidator id="CustomValidator1"
controltovalidate="txtEmailAddress"
OnServerValidate="ValidateEmailFormat"
errormessage="The email address format is not valid. Format: someone@company.com"
text=" *" runat="server" SetFocusOnError="True" />
</td>
Then with a custom validator, in the codebehind,
Code:
// Function: ValidateEmailFormat
// Description: Matches the Email expression, to ensure it is a valid format.
protected void ValidateEmailFormat(object source, ServerValidateEventArgs args)
{
// match the format
if (System.Text.RegularExpressions.Regex.IsMatch(txtEmailAddress.Text.ToString(), @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"))
args.IsValid = true;
else
args.IsValid = false;
}
First all thanks for your help, but I don't understand everything.
Do I have to replace anything from my code to use yours or do you I only have to add the last part?
If I do so I get the following errors: http://pastie.org/1155514
Sorry, but I'm absolutely a freshman to C-Sharp.
I hope you understand and can help me with my problem.
<td colspan="3" style="text-align: left">
<asp:TextBox ID="txtEmailAddress" runat="server" Width="241px" MaxLength="100"></asp:TextBox>
<asp:requiredfieldvalidator id="RequiredFieldValidator3"
controltovalidate="txtEmailAddress"
errormessage="Email Address."
text=" *" runat="server"
SetFocusOnError="True" />
<asp:CustomValidator id="CustomValidator1"
controltovalidate="txtEmailAddress"
OnServerValidate="ValidateEmailFormat"
errormessage="The email address format is not valid. Format: someone@company.com"
text=" *" runat="server" SetFocusOnError="True" />
</td>
Then with a custom validator, in the codebehind,
Code:
// Function: ValidateEmailFormat
// Description: Matches the Email expression, to ensure it is a valid format.
protected void ValidateEmailFormat(object source, ServerValidateEventArgs args)
{
// match the format
if (System.Text.RegularExpressions.Regex.IsMatch(txtEmailAddress.Text.ToString(), @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"))
args.IsValid = true;
else
args.IsValid = false;
}
-Quinn
I hope it helps! If it does please rate up.
So, the top portion goes into the .ASPX page.
The bottom part, goes into the corresponding .aspx.cs page.
Bookmarks