Hi,

Please anyone help me out............

I want the users to enter the data in the textbox of the minimum length of "10" and maximum length can be "ANY"(or above "10").

Thanks in advance...........................

Why not just validate on the postback and come back with an error message if it is <10 characters? I can't think of any website that enforces a minimum length validation browser side.

You can use a RegularExpression validation for this purpose.

<asp:TextBox ID="TextBox1" runat="server"  />
<asp:RegularExpressionValidator ID="regExTextBox1" runat="server" 
   ControlToValidate="TextBox1"
   ErrorMessage="Minimum password length is 10"
   ValidationExpression=".{10}.*" />
commented: or that +15

or you could use a custom validator:

this part in your asp page

<asp:TextBox id="txtTextBox" runat="server"/>
<asp:CustomValidator id="cvLengthValidator" runat="server" OnServerValidate="cvLengthValidator_OnServerValidate" ErrorMessage="Minimum Length is 10" ControlToValidate="txtTextBox"/>

in your code behind

protected void cvLengthValidator_OnServerValidate(object sender, ServerValidateEventArgs e)
{
       e.IsValid = e.Value.ToString().Length > 10;
}

You can use a RegularExpression validation for this purpose.

<asp:TextBox ID="TextBox1" runat="server"  />
<asp:RegularExpressionValidator ID="regExTextBox1" runat="server" 
   ControlToValidate="TextBox1"
   ErrorMessage="Minimum password length is 10"
   ValidationExpression=".{10}.*" />

Hi, Thanks for solution.....

Hi kailasgorane,

Please mark this thread as solved if your question is answered.

Regards
Ramesh. S

In Textbox i want to enter the India phone no The textbox take 10 digits only not more than one number

To resolve this issues.go for custom validator along with regexpression for phone number validating.To get the regular expression for phone number

Expression : ^((+)?(\d{2}[-])?(\d{10}){1})?(\d{11}){0,1}?$
Description : India phone number, accept with optional +91 national code and 0 for land and mobile number prefix . Allows optional - after national code

for more info Click Here

hope this will help you.

The suggetion of Ramesh for using Reguler Expression is really working . Thanks dude!!!

Thanks Ramesh.. It worked for me.

I've one more question can I check for value of the textbox like if value should be atleast 500 or more??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.