New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Strip HTML on Paste

This help article shows how to strip HTML tags from content that is pasted in RadEditor.

Follow these steps:

  1. Handle the OnClientPasteHtml event.
  2. Catch the Paste command.
  3. Obtain the content via the get_value() method of the event arguments and modify it as needed.
  4. Set the modified content via the set_value() method of the event arguments.

Example 1: Stripping <strong>, <em> and <span> tags on paste in RadEditor.

<telerik:RadEditor RenderMode="Lightweight" runat="server" ID="RadEditor1" OnClientPasteHtml="OnClientPasteHtml" />

<script>
    function OnClientPasteHtml(editor, args) {
        var commandName = args.get_commandName();

        // Paste command is the one that handles plain paste, e.g., when Ctrl+V is used.
        if (commandName === "Paste") {
            var htmlToBePasted = args.get_value(); // Get the value to be pasted

            // Use Regex to strip <strong>, <em> and <span> tags.
            htmlToBePasted = htmlToBePasted.replace(/<(\/)*(strong|em|span)[^>]*>/gi, "");

            // Set the processed content to the arguments.
            args.set_value(htmlToBePasted);
        }
    }
</script>

See Also

In this article