Factored out operator checking function.