Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. textbox check

textbox check

Scheduled Pinned Locked Moved C#
question
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NewToAspDotNet
    wrote on last edited by
    #1

    hi, I have a textbox. how can i avoid that a user types strings in it, bud only decimal values? thanx

    M P P A 4 Replies Last reply
    0
    • N NewToAspDotNet

      hi, I have a textbox. how can i avoid that a user types strings in it, bud only decimal values? thanx

      M Offline
      M Offline
      Matthew Cuba
      wrote on last edited by
      #2

      Djavid j wrote:

      I have a textbox. how can i avoid that a user types strings in it, bud only decimal values?

      MaskedTextBox could be used, or you could handle the Key events (KeyDown, KeyPress, KeyUp) and look at what was typed there, only allowing characters that pass your criteria through. There may be other ways. Good Luck!

      It isn't enough to do well in life. One must do good when and where one can. Otherwise, what's the point?

      1 Reply Last reply
      0
      • N NewToAspDotNet

        hi, I have a textbox. how can i avoid that a user types strings in it, bud only decimal values? thanx

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        Or use a NumericUpDown instead.

        1 Reply Last reply
        0
        • N NewToAspDotNet

          hi, I have a textbox. how can i avoid that a user types strings in it, bud only decimal values? thanx

          P Offline
          P Offline
          Peter Vertes
          wrote on last edited by
          #4

          When you convert the TextBox.Text value to a number make sure you catch InvalidCastExceptions which should indicate if the user input was too small/too big/not a number. Read this post, this should help you: http://iheartdotnet.blogspot.com/2007/09/cast-vs-doubleparse-vs-converttodouble.html[^]

          --- http://iheartdotnet.blogspot.com

          1 Reply Last reply
          0
          • N NewToAspDotNet

            hi, I have a textbox. how can i avoid that a user types strings in it, bud only decimal values? thanx

            A Offline
            A Offline
            Ajay k_Singh
            wrote on last edited by
            #5

            I think it is pretty easy to prevent user from entering any text value, we may use following lines of code in KeyPress event of Text box– private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (Char.IsLetter (e.KeyChar)) e.Handled = true; } I hope this helps:). -Dave.

            Dave Traister, ComponentOne LLC. www.componentone.com

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups