for me this would always be a matter of defining the acceptable characters...and if any part of input fails to meet criteria, then reject entire input. a human needs to check and fix the file/node. trying to instead cover all the cases of what's not acceptable, can be quite elusive, and prone to break in future.
the hardest line to type correctly is: stty erase ^H