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. Visual Basic
  4. Validating characters

Validating characters

Scheduled Pinned Locked Moved Visual Basic
questioncsharpregextutorial
2 Posts 2 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
    Mark06
    wrote on last edited by
    #1

    Hi, Im using .Net 2, creating a user entry form. How do I prevent 1 or more characters from being entered into a textbox. For example: one textbox, I dont want a user entering slashes or single quotes. In another textbox, I dont want the user entering single quotes. Have I got to write a whole validation thing, or is there some sort of formatting or regex I can use? Any response gratefully appreciated. Mark

    K 1 Reply Last reply
    0
    • M Mark06

      Hi, Im using .Net 2, creating a user entry form. How do I prevent 1 or more characters from being entered into a textbox. For example: one textbox, I dont want a user entering slashes or single quotes. In another textbox, I dont want the user entering single quotes. Have I got to write a whole validation thing, or is there some sort of formatting or regex I can use? Any response gratefully appreciated. Mark

      K Offline
      K Offline
      KeithF
      wrote on last edited by
      #2

      Hi Mark You can use regular expressions as far as i know to do what you want or you could use a masked textbox in .Net 2.0. However to do what you want you need to you use the keypress event of a textbox and ignore character you dont want to allow by setting e.handled = true. Private Sub txtText1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtText1.KeyPress 'If the key pressed is ' or " or any type of punctuation mark then do not allow If e.KeyChar.IsPunctuation(e.KeyChar) Then e.Handled = True End If End Sub 'This will ignore a backslash If e.KeyChar = Microsoft.VisualBasic.Chr(Keys.OemBackslash) Then e.Handled = True End If Hope this Helps Keith

      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