Replace invalid characters instead of keeping just some of the valid ones.