Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created textbox in gridview...I need to validate this textbox using javascript that should not allow character more than 200.


Can anyone help me......
Posted
Comments
Shahin Khorshidnia 28-Feb-12 8:23am    
Please accept the answer if it has helped

Use Length Attribute

JavaScript length Property[^]
 
Share this answer
 
function ValidText(evt,val)
      {
                  if (val.length>200)
                  return false;

         return true;
      }
in grid 

 <INPUT id="txtChar" onkeypress="return ValidText(event,this.value)" type="text" name="txtChar">
 
Share this answer
 
Refer to this similar CP question,

How to fix Character Length in a TextBox[^]

Hope it helps.
 
Share this answer
 
If you working with ASP.NET web controls, then TextBox have property called MaxLength. You can set that property to 200. You can find more information regarding MaxLength here[^]
 
Share this answer
 
Hi, call JS function on textbox. use below code for this:

ASP.NET
<asp:textbox id="txtBox" runat="server" width="150px" onkeypress="javascript:return isValidateLen(this);" xmlns:asp="#unknown"> </asp:textbox>


JS Function

JavaScript
function isValidateLen(txtID)
{
txtObj = document.getElementById(txtID);
if(txtObj.value.length < 200)
{
return true;
}
else
{
return false;
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900