Deduped check_str_validity implementations.