• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javascript:Restricting the user to paste in textbox

 
Chennarao Marvatu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also do something like this too

onchange="if(this.value.length>100)this.value=this.value.substring(0,100);"

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic