Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET3.0C#
sir i try to restrict textbox only contain 2 digit data but i get problem to do this task.......
 
i want, user put only two digit data in text box .....and when user put 3 digit of data then automaticaly one message show "u r only put 2 digit data in this text box".....
 
plz help me....
Posted 11-Aug-12 0:21am
Comments
Kenneth Haugland at 11-Aug-12 6:27am
   
Get the textinput and stop the event if the number of items in your textbox is larger than 2....
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

i solve my self.
 
textBox1.MaxLength = 2;
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
You can use TextBox's MaxLength property to restrict user to enter only 2 characters. To display message to user you can use TextChanged event of TextBox.
  Permalink  
Comments
shambhoo kumar at 11-Aug-12 6:38am
   
Thanks alot..............
Kenneth Haugland at 11-Aug-12 6:39am
   
Even better :) a 5.
shambhoo kumar at 11-Aug-12 6:40am
   
yes... :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try This:-
First set the MaxLength Property of Textbox to 2 and then write following the following code:-
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
     if (textBox1.Text.Length > 2)
     {
         MessageBox.Show("Can Enter only two Characters in this Textbox.", "Textbox", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
}
  Permalink  
v2

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 9,225
1 OriginalGriff 5,395
2 Peter Leow 4,100
3 Maciej Los 3,540
4 Abhinav S 3,333


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid