Added a method to validate user input