modified validation function to not allow spaces before or after the input