I assume that you need ASCII for printing, not just ASCII, so you probably want to limit yourself to 0x20 points through 0x7e:
if (Regex.isMatch (str, @"[^\u0020-\u007E]", RegexOptions.None)) { ... Show message box here ... str = Regex.Replace (str, @"[^\u0020-\u007E]", string.Empty); }
But I'm not sure if the message box is the right way. This can be very annoying. It might be better to have error control in your form somewhere that you can simply set an error message (and give it a signal) when the user enters an invalid character. When the user enters another (valid) character, reset, which controls the empty string. It seems much less intrusive.
paxdiablo
source share