6 Answers, 1 is accepted
0
Hello Tgaud,
Here is an example demonstrating how to restrict the text length in RadEditor:
Best regards,
Rumen
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Here is an example demonstrating how to restrict the text length in RadEditor:
<script type="text/javascript"> |
var maxTextLength = 30; |
var messageText = 'You are not able to type more than ' + maxTextLength + ' symbols!'; |
function isAlphaNumericKey(keyCode) |
{ |
if ((keyCode > 47 && keyCode < 58) || (keyCode > 64 && keyCode < 91)) |
{ |
return true; |
} |
return false; |
} |
function LimitCharacters(editor) |
{ |
editor.attachEventHandler ("keydown", function (e) |
{ |
e = (e == null)? window.event : e; |
if (isAlphaNumericKey(e.keyCode)) |
{ |
textLength = editor.get_text().length; |
if (textLength >= maxTextLength) |
{ |
alert(messageText); |
e.returnValue = false; |
return false; |
} |
} |
}); |
} |
function CalculateLength(editor, value) |
{ |
var textLength = editor.get_text().length; |
var clipboardLength = value.length; |
textLength += clipboardLength; |
return textLength; |
} |
function OnClientPasteHtml(editor, args) |
{ |
var commandName = args.get_commandName(); |
var value = args.get_value(); |
if (commandName == "PasteFromWord" |
|| commandName == "PasteFromWordNoFontsNoSizes" |
|| commandName == "PastePlainText" |
|| commandName == "PasteAsHtml" |
|| commandName == "Paste" ) |
{ |
var textLength = CalculateLength (editor, value); |
if (textLength >= maxTextLength) |
{ |
alert(messageText); |
args.set_cancel(true); |
} |
} |
} |
</script> |
<telerik:RadEditor id="RadEditor1" OnClientLoad="LimitCharacters" OnClientPasteHtml="OnClientPasteHtml" |
Runat="server"> |
<Content> |
</Content> |
</telerik:RadEditor> |
Best regards,
Rumen
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jeremy Coenen
Top achievements
Rank 1
answered on 25 Jun 2009, 03:31 PM
There appears to be flaws in this code as it does not count a number of
characters that I think should be checked. For example all of the
number pad numbers (0-9) are ignored, as well as period,comma, and a
host of other relevant characters. Below is my modified version of
isAlphaNumericKey
function isAlphaNumericKey(keyCode) { |
if ( |
(keyCode > 47 && keyCode < 58) || |
(keyCode > 64 && keyCode < 91) || |
(keyCode > 93 && keyCode < 112) || |
(keyCode > 185 && keyCode < 193) || |
(keyCode > 218 && keyCode < 223) |
) |
{ |
return true; |
} |
return false; |
} |
0
rick
Top achievements
Rank 1
answered on 11 Feb 2014, 05:58 PM
Hi
Is there no other way to limit text/html insertion without coding?
It seems wrong to have a Text / HTML char limit without being able to enforce it.
Is it possible to add a functionality/property, something like CanExceedMaxLength="false"?
Thank you
Is there no other way to limit text/html insertion without coding?
It seems wrong to have a Text / HTML char limit without being able to enforce it.
Is it possible to add a functionality/property, something like CanExceedMaxLength="false"?
Thank you
0
Hi Rick,
The above discussion is dated since 2009 year and could be quite outdated.
The RadEditor control has the MaxHtmlLength and MaxTextLength properties that could be helpful to restrict the content length. You can examine this help article for more information about them.
If you have further difficulties, please open a formal ticket to us with details about the encountered problems.
Regards,
Ianko
Telerik
The above discussion is dated since 2009 year and could be quite outdated.
The RadEditor control has the MaxHtmlLength and MaxTextLength properties that could be helpful to restrict the content length. You can examine this help article for more information about them.
If you have further difficulties, please open a formal ticket to us with details about the encountered problems.
Regards,
Ianko
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
0
rick
Top achievements
Rank 1
answered on 13 Feb 2014, 09:31 AM
Hi,
Yes, i know of the MaxHtmlLength and MaxTextLength properties, but they do not impede the user from exceeding that limit.
My question is if there is no alternative to the alert displayed when the limit is exceed, or implementing custom code myself.
Thank you
Yes, i know of the MaxHtmlLength and MaxTextLength properties, but they do not impede the user from exceeding that limit.
My question is if there is no alternative to the alert displayed when the limit is exceed, or implementing custom code myself.
Thank you
0
Hello Rick,
I am sorry for not understanding the origin of required information.
Unfortunately, the RadEditor control does not provide a built-in functionality for text length limitation. Such approach should be entirely custom implementation, which is built accordingly to the application requirements.
Although examining the Client-side API of the editor would help you to achieve the desired functionality.
Regards,
Ianko
Telerik
I am sorry for not understanding the origin of required information.
Unfortunately, the RadEditor control does not provide a built-in functionality for text length limitation. Such approach should be entirely custom implementation, which is built accordingly to the application requirements.
Although examining the Client-side API of the editor would help you to achieve the desired functionality.
Regards,
Ianko
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.