Throw exception if string contains invalid chars