Mobile Content

Saturday, December 24, 2011

Validate Textbox length using Javascript in asp.net

Validate length of Texbox upto 10 char


Example:


in .aspx page


<script type="javascript">
function count(text,long)
{
             var maxlength=new Number(long);
             if( text.value.length > maxlength )
             {
                      text.value= text.value.substring(0,maxlength);
                      alert("only"+long+"character");
             } 
}


</script>


<asp:TextBox id="TextBox1" runat="server"  onkeyup="count(this,10)" onchange="count(this,10)" TextMode="multiline"  />


o/p

Alert will be shown when character exceed 10 character

No comments:

Post a Comment