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