getopts help

First off, I apologize for my lack of knowledge. I realize my problem will probably seem pretty basic to everyone, but I've been at this for several hours now and I've gotten nowhere. I would contact my professor, but it is too late for that.

Anyway, I'm trying to write a function called CheckOptions which is passed a string of characters indicating which options may be used. In it, I use getopts to verify that the options are valid. Now from my understanding, in getopts when an unknown option is presented, OPTARG is set to that unknown option, however this does not seem to be the case for me. Am I wrong in assuming that this is done automatically?

CheckOptions()
{
        validOpts=$1
        shift
        while getopts $validOpts optLetter ; do
                echo $optLetter $OPTIND $OPTARG
        done
}

CheckOptions "abc" -a -b -d

if [[ $? -eq 0 ]] ; then
        echo OPTIND = $OPTIND
else
        echo OPTARG = $OPTARG
fi

not sure what you are tyring to do. but your getopts seems to be little out of picture to me. try something like below it will be helpful for you..

while $etopts S:M: options
do
case ${PARAMETERS} in
                S)      SOMETHING=$OPTARG;;
                M)      MORE=$OPTARG;;
                *)      ERROR=1
        esac
done

if [[ ${M_ERR} -gt 0 ]]
then
echo $"error in what ru doing???"
exit 
fi
#you have to call your script like below 

checkoptions -Sabc -Ma

and in your script you have to define what the parameter S and M suppose to do ??