1

I'm using CKEditor. To check if there's a value or not, I tried to use RequiredFieldValidator.

The RequiredFieldValidator works but not perfectly, I need to make sure the CKEditor doesn't contain anything, not even white-space.

The RequiredFieldValidator works when I type 1 or 2 space(s).

When I click the space button a third time and then click the submit button, the RequiredFieldValidator considers it valid, and data is posted.

So I created a CustomValidator, in the validation method, I remove all HTML tags, then I .Trim(), however, trimming isn't working, data is still posted, and even if I do field.Text.Trim().Length; the returned number isn't 0.

What needs to be done here?

The method that removes HTML tags.

public string StripTagsCharArray(string source)
    {
        char[] array = new char[source.Length];
        int arrayIndex = 0;
        bool inside = false;

        for (int i = 0; i < source.Length; i++)
        {
            char let = source[i];
            if (let == '<')
            {
            inside = true;
            continue;
            }
            if (let == '>')
            {
            inside = false;
            continue;
            }
            if (!inside)
            {
            array[arrayIndex] = let;
            arrayIndex++;
            }
        }
        return new string(array, 0, arrayIndex);
    }
4

2 回答 2

1

试试这个技巧:

WebUtility.HtmlDecode(field.Text).Trim();

为您的CustomValidator.

于 2013-08-29T17:20:56.543 回答
0

在 CKeditor 中试试这个config.js

config.htmlEncodeOutput=false;
于 2013-08-29T17:23:48.523 回答