Added logic to validate search input