Validate MaxLenght of multiline textbox on paste

Posted by Virendradugar under JavaScript category on | Views : 6466
Put this code onPaste event of the textbox. This code restricts user not to enter more than 255 characters. Let's us assume there are already 100 characters in the textbox and you copy some text which is of 500 characters then this code will not allow user to paste the data.

asp:TextBox ID="txtComments" runat="server" CssClass="textbox" Width="100%" TextMode="multiLine" onpaste="javascript:if(this.value.length+window.clipboardData.getData('Text').length>255){event.returnValue = false;};"></asp:TextBox>

Comments or Responses

Login to post response