max lenght validation of mutiline textbox

max lenght validation of mutiline textbox using below javascript functions



<asp:TextBox ID="txtbox" runat="server" TextMode="MultiLine" onkeypress="return textboxMultilineMaxNumber(this,200)" onbeforepaste="doBeforePaste(this,200)" onpaste="doPaste(this,200)"></asp:TextBox>







function textboxMultilineMaxNumber(txt,maxLen){
try{
if(txt.value.length > (maxLen-1))

return false;
}catch(e){
}
}



function doBeforePaste(control,maxLength)
{
if(maxLength)
{
event.returnValue = false;
}
}

function doPaste(control,maxLength)
{
value = control.value;
if(maxLength){
event.returnValue = false;
maxLength = parseInt(maxLength);
var o = control.document.selection.createRange();
var iInsertLength = maxLength - value.length + o.text.length;
var sData = window.clipboardData.getData("Text").substr(0,iInsertLength);
o.text = sData;
}
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: