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 Validation

TextBox Validation

Scheduled Pinned Locked Moved C#
question
4 Posts 4 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.
  • M Offline
    M Offline
    Muhammad Waqas Butt
    wrote on last edited by
    #1

    How make validatin that whitespace are not allowed in textbox? How i get the key code of press key?

    L 1 Reply Last reply
    0
    • M Muhammad Waqas Butt

      How make validatin that whitespace are not allowed in textbox? How i get the key code of press key?

      L Offline
      L Offline
      Luis Alonso Ramos
      wrote on last edited by
      #2

      There are two different things you can do: 1. Handle Validating event for the TextBox, and use regular expressions to validate that no spaces are in the string the user entered, and if yes, don't allow the user to go to another control before correcting it. 2. In the KeyDown event, if the key is a space, set e.Handled = true, so the TextBox doesn't handle it, effectively eating the keystroke. -- LuisR


      Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

      M 1 Reply Last reply
      0
      • L Luis Alonso Ramos

        There are two different things you can do: 1. Handle Validating event for the TextBox, and use regular expressions to validate that no spaces are in the string the user entered, and if yes, don't allow the user to go to another control before correcting it. 2. In the KeyDown event, if the key is a space, set e.Handled = true, so the TextBox doesn't handle it, effectively eating the keystroke. -- LuisR


        Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

        M Offline
        M Offline
        maheshfour
        wrote on last edited by
        #3

        i tried using this but it does not work i tried using this sample code. private void textBox1_KeyDown(object sender,System.Windows.Forms.KeyEventArgs e) { if(e.KeyValue==65) { e.Handled=true; } } it still prints the character 'a' in the text box

        A 1 Reply Last reply
        0
        • M maheshfour

          i tried using this but it does not work i tried using this sample code. private void textBox1_KeyDown(object sender,System.Windows.Forms.KeyEventArgs e) { if(e.KeyValue==65) { e.Handled=true; } } it still prints the character 'a' in the text box

          A Offline
          A Offline
          ameto
          wrote on last edited by
          #4

          tyutyutryryr ghfgh fghfghf ghfgh fgh f gh fg hf gh f h gfh

          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