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

Limit Textbox number of lines

2 Answers 89 Views
Input
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 2
Scott asked on 19 Dec 2008, 06:53 PM
Is there any way to limit the number of lines (not character length) in a textbox? 

2 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 19 Dec 2008, 08:37 PM
Hello Scott,

I am not sure what do you mean by "number of lines" - is it the number of carriage returns (created by pressing the Enter key) or the number of places where the input string splits to a new line? I am not aware of a way to count the second number, however, I can research this if needed.

However, if you want to count the number of carriage returns, you can try using some Javascript. Please subscribe to the RadTextBox' OnKeyPress client event, get the current value of the textbox and count the new lines. For example:

[Javascript]

var newLines = 0;

for (var j = 0; j < textboxvalue.length; j++)
{
    if (textboxvalue.charCodeAt(j) == 10)
    {
        newLines++;
    }
}



All the best,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Scott
Top achievements
Rank 2
answered on 19 Dec 2008, 08:47 PM
Yes, I was thinking more of carriage return.  I'll give your code a try and thank you for the response.
Tags
Input
Asked by
Scott
Top achievements
Rank 2
Answers by
Dimo
Telerik team
Scott
Top achievements
Rank 2
Share this question
or