Added a function for validating user inputs when prompted.