[?] Define an option or an argument whose values are confined?

Hello everyone, I want to define a function whose arguments or options can only be selected in a range. For example:

Options[TestFunction]={problemID->1};       
TestFunction[x_, opts:OptionsPattern[]]:=Module[{},...];

Here, the problemID must one value of {1, 2, 3, 4}, and the default value is 1.

My question is how to define such argument or options. For example, that is the argument like the second argument of build-in function Import[], whose second argument can only be selected in {Element, Data, List, CSV, … and so on}.

Thank you very much!

This is kind of tricky for options what generally happens is that the function throws a message when the options are not correct (out of bound). See for example how it is done in the built-in Plot function, you can see how the arguments are parsed et cetera:

Needs["GeneralUtilities`"]
Plot[Sin[x], {x, 0, 1}];
PrintDefinitions@System`ProtoPlotDump`iPlotLayer1
PrintDefinitions@System`ProtoPlotDump`iPlot

You might try the definition, like e.g.:

testFunction[x_, problemID_: 1] := (whatEverFunctionBody[x, problemID]) /; MemberQ[ {1, 2, 3, 4}, problemID]

That is one way of doing it, but that’s not an option :wink: