2010-12-17 70 views
0

我想修改下面的自定义验证程序,以便它检查RadEditor不是空的,或者不仅包含像br和p标签等HTML标签,而且它必须是一些文本,而不是只是HTML标签。我如何实现我想要的?关于自定义验证

<asp:CustomValidator runat="server" ID="CustomValidator1" ControlToValidate="RadEditor1" ClientValidationFunction="checkLength">* The text length should not exceed 50 symbols.</asp:CustomValidator> 
<script type="text/javascript"> 
    var limitNum = 50; 

    function checkLength(sender, args) 
    { 
     //Note that sender is NOT the RadEditor. sender is the <span> of the validator. 
     //The content is contained in the args.Value variable  
     var editorText = args.Value; 
     args.IsValid = editorText.length < limitNum; 
    } 

事情是当我使用RadEditor所需的字段验证器时,br标记被存储为值,因此验证失败。那么,如何编写一个自定义验证器来检查编辑器是否只有html标签?

回答

1

使用jQuery它是如此简单:

args.IsValid = $(editorText).text().length < limitNum; 

的jQuery的text方法将删除所有的标签,让你只用“纯文本”。

+0

lemme试试这个..thnx – Serenity 2010-12-17 11:23:52