[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1231
  • Last Modified:

Maximum and minum length of textbox

How to set the maximum and minimum length of textbox...
Client side not server side...
0
PagodNaUtak
Asked:
PagodNaUtak
1 Solution
 
Gurvinder Pal SinghCommented:
0
 
thepanchCommented:
maximum length displayed at screen
size=number
maximum characters to receive on the textbox
maxlength=number
0
 
kosturdurCommented:
Hi,
Solutions from
http://geekswithblogs.net/mahesh/archive/2007/12/27/asp.net-textbox.multiline-maxlength.aspx
with little changes;

Solution Number 1 for
ASP.NET TextBox.MultiLine maxlength
Add following javascript

<script type="text/javascript" language="javascript">
/* <![CDATA[ */
function Count(text,long)
{
   var maxlength = new Number(long); // Change number to your max length.
  if(document.getElementById('<%=textBox.ClientID%>').value.length > maxlength)
  {
     text.value = text.value.substring(0,maxlength);
     alert(" Only " + long + " chars");
}
/* ]]> */
</script>
 
Where “textBox” is the asp text box ID.
Also add following events in your textbox.

onKeyUp="javascript:Count(this,200);" onChange="javascript:Count(this,200);"

Your textbox code should look like
<asp:TextBox ID="textBox" onKeyUp="javascript:Count(this,2);" onChange="javascript:Count(this,2);"  TextMode=MultiLine Columns="5" Rows="5" runat=server>
    </asp:TextBox>
 
Solution Number 2 for
ASP.NET TextBox.MultiLine maxlength
Another way to achieve this is regular expression. You can add following regular expression validate on asp text box.

<asp:RegularExpressionValidator ID="txtConclusionValidator1" ControlToValidate="textBox" Text="Exceeding 200 characters" ValidationExpression="^[\s\S]{0,2}$" runat="server" />

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
DhaestCommented:
Creating a TextBoxLengthValidator Validator Control
http://www.4guysfromrolla.com/articles/112404-1.aspx
0
 
Neeraj SoniSr. ArchitectCommented:
you can add MaxLength=10 which will restrict entering char after 10 chars in txtbox.

You have to add validator on txtbox for minlength.
0
 
PagodNaUtakAuthor Commented:
@neerajsoni,
Max length does not work in multiline textbox...
0
 
thepanchCommented:
no it doesnt because it only allows one line, so if you are triying to limit the character count (enter key counts as one) you'll have to do as kosturdur says with the count function.
0
 
puru1981Commented:
you can use regexvalidator to define min and maxlength {minlength,maxlength}

like

^[a-zA-Z.]{2,30}$
0
 
kosturdurCommented:
I need the points man to ask some question :(
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now