public boolean isSelectionValid(ProgramSelection selection, InstructionSearchDialog dialog) {

		// Users should not call this will a null selection but we need to check just in case.
		if (selection == null) {
			return false;
		}

		// First clear out the message panel if anything was being displayed there because of a
		// previous search.
		dialog.clearMessage();

		// Users can't select multiple regions or pick a region larger than MAX_SELECTION_SIZE, so
		// immediately return and display an error message if they do.
		if (selection.getNumAddresses() == 0) {
			dialog.displayMessage(
				"Select instructions from the listing (and hit reload/add) to populate the table.",
				Messages.NORMAL);
			return false;
		}
		if (!isSelectionSizeValid(selection)) {
			dialog.displayMessage("Invalid selection.  Cannot select more than " +
				MAX_SELECTION_SIZE + " instructions and/or data items.", Messages.ERROR);
			return false;
		}

		try {
			if (isSelectionRangeValid(selection)) {
				return true;
			}
		}
		catch (InvalidInputException e) {
			dialog.displayMessage(e.getMessage(), Messages.ERROR);
			return false;
		}

		return true;
	}
Checks the selection made by the user to make sure it is within
acceptable bounds regarding size and number of ranges.

@param selection the user selection
@param dialog the parent dialog
@return true if the selection is valid
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/instructionsearch/InstructionSearchPlugin.java