Click here to Skip to main content
15,041,548 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi frnds,

how to validate the Textbox with numbers. User should not enter alphabets or other characters...ONLY HE SHOULD ENTER $ DIGIT NUMBER.

user must enter only 4 digits as 2010.

So, how can we do this, do u have idea, please give me a good solution.

Thanks.
Posted

1 solution

Try this:
C#
void CharacterValidation(object sender, KeyPressEventArgs e)
       {
           if ((e.KeyChar >= 65 && e.KeyChar <= 90) || (e.KeyChar >= 97 && e.KeyChar <= 122) || e.KeyChar == 32 || e.KeyChar == 8 || e.Keychar != 36)
           {
               e.Handled = false;
           }
           else
           {
               e.Handled = true;
           }
       }


user must enter only 4 digits as 2010.
You need to set textBox1.MaxLength = 4;
   
v3
Comments
Prasad_Kulkarni 5-Jul-12 3:14am
   
No reason & a down-vote from Scholar Member.

Not fair enough.

You MUST have to give reason for down-vote.
[no name] 5-Jul-12 4:51am
   
+5
Prasad_Kulkarni 5-Jul-12 5:21am
   
Thank you!

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900