updated isValidQuery()- combined all validation in single regular expression