function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gopal ChatGopal Chat 

In a page I have Comment section recordtype is textarea,In that i want to stp paste after its word length become 255

but i can write and paste before 255 words
NagendraNagendra (Salesforce Developers) 
Hi Gopal,

Please try the below piece of code and let us know if this works for you.
<apex:page controller="ATestCase">
<script>
function checkLimit(limitField, limitCount, limitNum)
{
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } else {
        limitCount.value = limitNum - limitField.value.length;
    }
}
</script>
<apex:form >
<apex:pageBlock title="Text Limit">
<apex:pageBlockSection columns="1" >

<apex:inputTextarea value="{!myVar}" onkeydown="checkLimit(this,this.form.countdown,255);" &nbsp;<br>onkeyup="checkLimit(this,this.form.countdown,255);" onchange="checkLimit(this,this.form.countdown,255);"/>

<font size="1">(Maximum characters: 255)<br/>
You have <input readonly="true" type="text" name="countdown" size="3" value="255"/> characters left.</font>
</apex:pageBlockSection> 
</apex:pageBlock>
</apex:form>
</apex:page>
The above sample code will also handle Right Click and Paste (if greater than 255) because of an onchange event.

Let me know if it works for you.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra