Click here to Skip to main content
14,424,386 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,

I'm using .net 4.0 with C#. In text box when we enter numbers that text box accept only below 24 numbers!( If we enter 25, 26,27... these numbers will no display in that text box) , at the same time that text box accepts two decimals only (Ex: 12:00,1:00.....).

It is possible to do this? Can any one pls help me !!
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Use the RangeValidator control on the textbox.
In this example[^], only values between 30 and 40 are accepted.
   
Comments
Uday P.Singh 16-Dec-11 3:18am
   
5ed :)
Abhinav S 16-Dec-11 3:22am
   
Thank you Uday.
RaviRanjanKr 16-Dec-11 3:37am
   
5+
Abhinav S 16-Dec-11 3:42am
   
Thanks Ravi.
thatraja 16-Dec-11 3:47am
   
5!
Abhinav S 16-Dec-11 3:49am
   
Thanks thatraja.
Rate this:
Please Sign up or sign in to vote.

Solution 2

Alternatively you can use regular expressions[^]. Use RegularExpressionValidator Control[^]
   
Comments
RaviRanjanKr 16-Dec-11 3:37am
   
5+
Abhinav S 16-Dec-11 3:42am
   
5!
Rate this:
Please Sign up or sign in to vote.

Solution 3

To set textbox property as maxlenghth=24
   
Comments
[no name] 16-Dec-11 4:55am
   
Where can i declare?
<asp:TextBox ID="TextBox1" runat="server" maxlenghth="24">

is it correct?
[no name] 16-Dec-11 6:02am
   
it will set maxlength to text box.
if we enter 25 it will aceepted na?
that mean we can enter 24 character maximum in the textbox
[no name] 16-Dec-11 6:03am
   
for the given result we have to used regular expression validator.
it is best.
thank u.

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100