Factorize string type check