Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

[C#] A TextBox that only accepts numbers

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
11,299
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Jul 5, 2010

In this video, I'll show you how to make a TextBox that only accepts numbers and backspace in C#.

Sorry for my poor english and my bad voice.. My primary language is french.

The code can be found here :

http://charnycoding.pastebin.com/1uMuf6mZ

In this video, I'm using Visual C# 2008 and MS visual keyboard.

If you need some C# advices or help, you can contact me at the following email :

CharnyCoding@Hotmail.com

  • likes, 1 dislikes

Link to this comment:

Share to:
see all

All Comments (18)

Sign In or Sign Up now to post a comment!
  • This vid went viral on Liechtenstein

  • Thanks

  • @sachintha1991 I don't know i you solved it yet, but you misspelled it is KeyPressEventArgs

  • thank you. took me a year to get this done.

  • @jorgemaiadin : if (!Char.IsDigit(input) && input != 8 && input != 46 && input != 45)

    Follow the code above. ASCII Character for negative is 45 so exempt it form validation as he did for back space and I also changed to accept decimal values with period . that has ASCII code as 46.

  • Thank you so much. This really helped me out. Nice and simple code.

  • Wow sorry, i was on my iphone and read the code wrong :( works now :D

  • Thanks! But why is my backspace not working? I went over it several times and i swear i have same as u

  • Thanks........

  • hey when i try this program ..it trows an error on that e.KeyChar thing..i dont know the reason can u please help me

    the error is

    Error 1 'System.Windows.Forms.KeyEvent­Args' does not contain a definition for 'KeyChar' and no extension method 'KeyChar' accepting a first argument of type 'System.Windows.Forms.KeyEvent­Args' could be found (are you missing a using directive or an assembly reference?)

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more