improve string validation function