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. Windows Forms
  4. Text box validation

Text box validation

Scheduled Pinned Locked Moved Windows Forms
csharphelpquestion
3 Posts 2 Posters 7 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.
  • R Offline
    R Offline
    Ruchi03
    wrote on last edited by
    #1

    How do i restrict user from entering any alpahabet or special characters in my textbox, in the textbox key press event. I need to give a error message and no alphabets or special charaters should get printed.(in visual C#).its a window form.

    P 1 Reply Last reply
    0
    • R Ruchi03

      How do i restrict user from entering any alpahabet or special characters in my textbox, in the textbox key press event. I need to give a error message and no alphabets or special charaters should get printed.(in visual C#).its a window form.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      I'm not sure which characters you wish restricting. I'm assuming you're saying you only want numeric keypresses here. In the keypress event, you add the following code:

      if (!char.IsDigit(e.KeyChar))
        e.Handled = true;
      

      If you want to display an error message, you should use the error provider component and set its text at the same point that you set the e.Handled flag.

      Deja View - the feeling that you've seen this post before.

      R 1 Reply Last reply
      0
      • P Pete OHanlon

        I'm not sure which characters you wish restricting. I'm assuming you're saying you only want numeric keypresses here. In the keypress event, you add the following code:

        if (!char.IsDigit(e.KeyChar))
          e.Handled = true;
        

        If you want to display an error message, you should use the error provider component and set its text at the same point that you set the e.Handled flag.

        Deja View - the feeling that you've seen this post before.

        R Offline
        R Offline
        Ruchi03
        wrote on last edited by
        #3

        Thanks a lot..:). It worked..

        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