0

I use onkeypress="return this.value.length" that working fine. but i do copy and paste it keep on putting data in the text box. it should work for copy-paste operation too.

what i need to do for copy-paste operation to work for that too!

4 Answers 4

1

If you are looking for a way to limit what characters can be entered into a text box, you may find that the AjaxControlToolKit can help. It has a control called Filtered Textbox contro. Take a look at http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/FilteredTextBox/FilteredTextBox.aspx

Sign up to request clarification or add additional context in comments.

4 Comments

yes exactly i was looking for that! but how i use that as to restrict user to enter specific number of character? i search on that but not find!
This can be done without any extenders or javascript. If you are using ASP.Net, just set the max length, like this: <asp:TextBox Text="some text" ID="myId" runat="server" MaxLength="5" ></asp:TextBox>
but in the case of multiline text box. which become textarea when render on server. and html textarea does not support max length. then what should i do??? is filtered textbox give me the solution? actually "onkeypress=return this.value.length < 80" works fine but not work for copy-paste operation. its keep pasting even characters exceed from 80.
I'm not sure if the filtered textbox extender can limit the size. You can also try RegularExpressionValidator control: forums.asp.net/t/1170096.aspx/2/10
1

Use below code to find length while typing

<input type="text" onkeyup="alert(this.value.length)" / >

Hope it helps !! :)

Comments

0

use onchange with onkeypress. so that whatever you have put there also executes on change

Comments

0

I think ontextchanged="" could cover it

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.