• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

javascript:Restricting the user to paste in textbox

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic