I am creating an application which will send the input string to mobile device. Some devices have problems with encoding special characters so I would like to create a filte
I'm assuming you need printable ASCII rather than just ASCII, so you'd probably want to limit yourself to the 0x20 thru 0x7e code points:
if (Regex.isMatch (str, @"[^\u0020-\u007E]", RegexOptions.None)) {
... Show message box here ...
str = Regex.Replace (str, @"[^\u0020-\u007E]", string.Empty);
}
But I'm not convinced a message box is the right way to go. That could get very annoying. It may be better to have an error control on your form somewhere that you can just set to an error message (and beep to let them know) when the user enters an invalid character. When the user enters another (valid) character, reset that control to an empty string. That seems far less obtrusive.