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. How to discard invalid (ASCII 0-32) user input in editbox? [modified]

How to discard invalid (ASCII 0-32) user input in editbox? [modified]

Scheduled Pinned Locked Moved C#
csharptutorialquestion
3 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.
  • S Offline
    S Offline
    SandeepN
    wrote on last edited by
    #1

    I created simple DialogBased Windows application using C# I want to check if user has entered any control characters in the edit box. For Ex: in the edit box user can enter value like ALT + 8 (BackSpace) ALT + 9 (Horixontal Tab ) etc Though it looks funny but I want to discard this input. I tried to convert the string to int and check ASCII it did not work EX: Int32 nLength = str.Length; for(int i=0;i 0 ) Discard the input; } In this scenario for ALT + 8 I get asciival as 9688 ALT+9 as 9675. This is to check whether control characters entered? Why do I get ALT+8 as 9688 not as 8 asci value ? I want to basically check if user has entered any control characters like 1-32 or 127 ASCII value (Ex: ALT + 127) in the edit box. And discard the same. FYI this edit box should allow any other non english characters like French, German, Chinese, Japanese etc -- modified at 17:44 Tuesday 10th April, 2007

    Thanks, Sandeep Naik

    K 1 Reply Last reply
    0
    • S SandeepN

      I created simple DialogBased Windows application using C# I want to check if user has entered any control characters in the edit box. For Ex: in the edit box user can enter value like ALT + 8 (BackSpace) ALT + 9 (Horixontal Tab ) etc Though it looks funny but I want to discard this input. I tried to convert the string to int and check ASCII it did not work EX: Int32 nLength = str.Length; for(int i=0;i 0 ) Discard the input; } In this scenario for ALT + 8 I get asciival as 9688 ALT+9 as 9675. This is to check whether control characters entered? Why do I get ALT+8 as 9688 not as 8 asci value ? I want to basically check if user has entered any control characters like 1-32 or 127 ASCII value (Ex: ALT + 127) in the edit box. And discard the same. FYI this edit box should allow any other non english characters like French, German, Chinese, Japanese etc -- modified at 17:44 Tuesday 10th April, 2007

      Thanks, Sandeep Naik

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

      Is there some reason you are not using the keydown event? That give you access to if a alt key is pressed. You can return #0 and it will be like then didn't even type a key. msdn link: http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.keydown.aspx[^] Hope that helps. Ben

      S 1 Reply Last reply
      0
      • K kubben

        Is there some reason you are not using the keydown event? That give you access to if a alt key is pressed. You can return #0 and it will be like then didn't even type a key. msdn link: http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.keydown.aspx[^] Hope that helps. Ben

        S Offline
        S Offline
        SandeepN
        wrote on last edited by
        #3

        Thanks for your reply. Thats a good suggestion I appreciate it. But I don't want to restrict use from entering value like ALT + 65 , ALT + 117 which is valid value Actualy I am sending this value to COM object as BSTR. That is where I have my business logic written to validate the data entered. So I wanted to first figure out how to do it in C# and then mimic the similar code in C++. I found one website where they have table to show DOS equalent characters. But I want to good technique to check the same http://petesguide.com/WebStandards/entities/XHTML1.0-UTF-Latin-1entities.html[^] -- modified at 18:46 Tuesday 10th April, 2007

        Sandeep Naik

        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