Textbox Length
How can set Minimum and Maximum length to textbox either in design time or Runtime?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ravi ShekharRank #673 · 3.6K reputationPosted May 8, 2013, 10:39 PM EDT
if(textbox.text.length<5 && textbox.text.length>0)
{
// code here
}
else
{
// code here
}
regards,
ravi
VulpesRank #55 · 29.2K reputationPosted May 9, 2013, 2:29 AM EDT
However, there is no corresponding MinLength property.
Jignesh TrivediRank #16 · 50.3K reputationPosted May 9, 2013, 4:16 AM EDT
agree with Vulpe. thereis no property for set the minimum length of text box.
In this you can use validation control if you are working with ASP.net
please refer
http://www.daniweb.com/web-development/aspnet/threads/224762/how-to-set-the-minimum-and-maximum-lengh-of-the-textbox
hope this will help you.
Bineesh ViswanathRank #1,681 · 907 reputationPosted May 10, 2013, 12:23 AM EDT
Riddhi ValechaRank #794 · 2.9K reputationPosted May 10, 2013, 5:06 AM EDT
---------------
public const int minlen=5;
public const int maxlen=10;
if(textbox1.lenght < minlen)
{
messagebox.show("less than minimum lenght");
}
if(textbox1.lenght > maxlen)
{
messagebox.show("more than maximum lenght");
}
if(textbox1.lenght >= minlen && textbox1.lenght <= maxlen)
{
messagebox.show("proper lenght");
}
-----------
Hope this helps. Just set min and max lenght as per your requirements as constants variables.
constants variables - whose values cannot be changed.