Pregunta

I have a textbox that will end up being the body of an email. The problem I am having is some people are placing links within this textbox and when the email goes out there are a bunch of hyperlinks in the body. I want to prevent that from happening by validating the textbox so when it see's text containing "http://" in the textbox to prompt the user to remove any links inside the textbox before they can continue.

I need IsBodyHtml = true to be set because I have an image that automatically gets inserted in the body as well. So disabling isn't an option for me at the moment.

<strong>Alert Description</strong><br>
<asp:TextBox ID="AlertDesTxtBox" Rows="15" Width="450" TextMode="MultiLine"
             runat="server" />
<asp:RequiredFieldValidator id="RFV3" runat="server" ControlToValidate="AlertDesTxtBox"
             ErrorMessage="Description is required."
             ForeColor="Red">
</asp:RequiredFieldValidator>

Any suggestions? CustomValidator?

¿Fue útil?

Solución

You can easily search for "http://":

int startIndex = 0, remaining = textBox.Text.Length;

while ((startIndex = textBox1.Text.IndexOf(startIndex, textBox.Text.Length - startIndex)) > 0)
{
    MessageBox.Show("There is a link in here");
    startIndex++;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top