开发者

regarding Custom validation

I want to modify the custom validator below so it checks that the RadEditor is not empty OR doesn't only contain HTML tags like br and p tag , etc..there HAS to be some Text in it and not开发者_开发问答 just HTML tags. How do I achieve what I want ?

<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;  
    } 

The things is when I use required field validator with the RadEditor, br tag is stored as a value and hence validation fails. So how do I write a custom validator that checks that editor doesnt only have html tags in it??


Using jQuery it's as simple as this:

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

The text method of jQuery will remove all tags and leave you with the "pure text" only.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜