Update the way of trimming space and optimze the avoid script validation