It's not a secret anymore!
The moose likes HTML, CSS and JavaScript and the fly likes javascript:Restricting the user to paste in textbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "javascript:Restricting the user to paste in textbox" Watch "javascript:Restricting the user to paste in textbox" New topic

javascript:Restricting the user to paste in textbox

Chennarao Marvatu
Ranch Hand

Joined: Aug 09, 2004
Posts: 32
Hello Gurus,
In the Textbox and Textarea there is max length limit.I have validated when the user TYPE more than the max . But when the copy and paste it is allowing.
So i want the user to restrict when he paste the data in the TExtarea or textbox itself .Please suggest me.

Keith Sebastian

Joined: Mar 10, 2005
Posts: 9
For a textbox (element input, type text), maxlength is part of the HTML Specification (link), and is does not even require javascript turned on to properly work. As a test I just tried to copy/paste into a text box with maxlength set, and it didn't paste past the maxlength. Even in a browser as old as Netscape 2.

Now, textareas. That's a different story. If you look at the textarea spec, you'll notice there is no maxlength. If you want to limit characters in a textarea, you'll need to use javascript. Is this where you're having a problem?
[ September 05, 2005: Message edited by: Keith Sebastian ]
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
You could also do something like this too


I agree. Here's the link:
subject: javascript:Restricting the user to paste in textbox
jQuery in Action, 3rd edition