Click here to Skip to main content
11,715,491 members (86,110 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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 4-Jul-12 20:46pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Check following links
1) try this[^]

2)check it[^]

3) this also[^]
may be this help you

Thank you
ChetanV
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try this:
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;
  Permalink  
v3
Comments
Prasad_Kulkarni at 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.
2irfanshaikh at 5-Jul-12 4:51am
   
+5
Prasad_Kulkarni at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 518
1 Richard MacCutchan 300
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 785
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320


Advertise | Privacy | Mobile
Web03 | 2.8.150901.1 | Last Updated 5 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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