tags:

views:

41

answers:

2

I am looking for a text editor for my asp.net mvc project. I was able to find a lot of text editor out there works pretty well.

What I am looking for is a editor that accept only regualr character like "I am a superman". I do not want to save "<p><strong>I am a superman</strong></p>" into my SQL table since I have to show it thru textbox(example : <%= Html.TextBox("Remark", Model.empExperience.Remark)%>).

Let me know.

+2  A: 

Seeing as you do not wish to allow HTML, your best bet is to simply have a means of stripping HTML from the provided input. There's no need to implement a custom text editor for this sort of thing.

Have a look at: http://stackoverflow.com/questions/785715/asp-net-strip-html-tags/785743#785743

Nathan Taylor
Your answer sounds right, but it looks complicate to use "<[^>]*>". Let's say there is a HTML string "<p>I worked.</p><p></p><p></p>". How do you convert it to "I worked" by using "<[^>]*>"? I tried with many sample code from the link that you provided, but I could not make it work.
Hoorayo
If that's your string, you would have to decode it first, e.g. HttpUtility.HtmlDecode(myHtmlEncodedString) before using the RegEx
JustinStolle
I did HttpUtility.HtmlDecode(myHtmlEncodedString) and I also Iadded Regex.Replace(myHtmlEncodedString, @"<(.|\n)*?>", string.Empty). It worked out. Thanks Nathan and JustineStolle
Hoorayo
+1  A: 

This is how you do it (to sum up the answers on the link Nathan provided):

    private static readonly Regex StripHtml = new Regex("<[^>]*>", RegexOptions.Compiled);

    /// <summary>
    ///     Strips all HTML tags from the specified string.
    /// </summary>
    /// <param name = "html">The string containing HTML</param>
    /// <returns>A string without HTML tags</returns>
    public static string StripHtmlTags(string html)
    {
        if (string.IsNullOrEmpty(html))
            return string.Empty;

        return StripHtml.Replace(html, string.Empty);
    }
mare