This is a migrated thread and some comments may be shown as answers.

Restrict user from entering not more than 250 characters

5 Answers 145 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Naveen T
Top achievements
Rank 1
Naveen T asked on 09 Nov 2010, 11:39 AM
Hi,

How to restrict the user from entering not more than 250 characters,not allow users to drop images in radrichtextbox.

Regards,
Nav

5 Answers, 1 is accepted

Sort by
0
Mike
Telerik team
answered on 11 Nov 2010, 09:26 AM
Hi Nav Kum,

Can you please elaborate a bit more on your scenario? The major issue about limiting RadRichTextBox content size is that this size varies a lot depending of the output format you may choose. Actually the size of the document cannot be determined when typing characters but only when the document is exported. We are looking forward to your response.

Greetings,
Mike
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Naveen T
Top achievements
Rank 1
answered on 11 Nov 2010, 12:16 PM
Hi,

I would like to perform Ui validation with radrichtextbox,not allowing/restricting the user while typing text(not more than 250 chratcters).output format is HTML (can add all sort things available in tool bar).could you please suggest me any other alternative.


Regards,
Nav

0
Mike
Telerik team
answered on 11 Nov 2010, 12:51 PM
Hi nav kum,

I am sorry but I need a bit more information about this case. What would you do with the Html document after the user edit it? Eg.g. save it in a database where you have restrictions in the size of the field to 250 chars? Or you simply need to restrict user not to enter too much text. I am asking this because these cases are very different. For example an Html document with 250 chars of text can actually become even several thousand of  chars if the document is heavily formatted.
Anticipating your response.

All the best,
Mike
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Michael
Top achievements
Rank 1
answered on 30 Nov 2010, 09:34 PM
I have a similar situation.  I'be been asked to limit the length of the plain text to 1800 characters, and the length of the html to 3200 for a rad rich text box, but as of yet I haven't been able to pull it off.

I have been able to limit the input by using the on key press function and checking the TxtFormatProvider and HtmlFormatProvider.  The problem I have is that when copy and paste is used, it can surpass that limit.

Thanks,
Mike
0
Iva Toteva
Telerik team
answered on 02 Dec 2010, 09:08 AM
Hi Michael,

RadRichTextBox does not provide the functionality that will enable you to limit the text input's size out of the box. There are indeterministic cases that would arise if we were to implement it.
A good example is your case - the HTML output can grow if you change the style of the already inserted text. Thus, you can exceed the limits you have set without entering new symbols. What would you prefer to happen then - deny the applying of the new formatting or delete the text at the end?

Just a thought - don't you think that it will be better if you allowed users to exceed the limit while editing the text they input, and perform the validation when they try to leave/ save the field?

Otherwise, a workaround might be to handle the DocumentContentChanged event and undo the last change in the document if the size exceeds the limit. Something like:

private void radRichTextBox_DocumentContentChanged(object sender, EventArgs e)
   {           
        TxtFormatProvider provider = new TxtFormatProvider();
        while(provider.Export(this.radRichTextBox.Document).Length > MAX_LENGTH)
        {
             this.radRichTextBox.Undo();
        }
   }
However, the text will be inserted (on Paste, for example) and then deleted, which will be visible by the user.
If you have any other questions, do not hesitate to contact us again.

Greetings,
Iva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
RichTextBox
Asked by
Naveen T
Top achievements
Rank 1
Answers by
Mike
Telerik team
Naveen T
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Iva Toteva
Telerik team
Share this question
or