More secure regex type check