validation against special characters

I have a criteria like bloew.
user entered the uid like <START_UID>-<END_UID>
it menas if he enter 00001-12345
START_UID=00001 and END_UID=12345
both are separated by `-`.
I need to validate whether user entered uids like above, he should have to enter '-', otherwise error msg has to print. And need to validate whether both uids are numeric only. If he enter 00001-1234( error msg has to print. And it should accepts only one occurance of '-' symbol.
can any one give the solution.I am trying with this sol
OPTARG=$1
cnt=1;
while [ $cnt -le $length ]
do
c=$(echo "$OPTARG"|cut -c$cnt-$cnt)
if [[ $c = "-" ]]
then
FIRST_FIELD=${OPTARG%%-}
SECOND_FIELD=${OPTARG##
-}
fi
((cnt+=1))
done
But when i enter 3663-929(
-bash: syntax error near unexpected token `('
This error am getting .

Thanx

Hi ,
Please try below

OPTARG=$1
echo $OPTARG
len="`echo ${#OPTARG}`"
echo $len
cnt=1
while [ $cnt -le $len ]
do
c=$(echo "$OPTARG"|cut -c$cnt-$cnt)
if [[ $c = "-" ]]
then
FIRST_FIELD=${OPTARG%%-}
SECOND_FIELD=${OPTARG##
-}
fi
((cnt+=1))
done
echo $FIRST_FIELD
echo $SECOND_FIELD

Hi ,

U have sent the same code what i posted. Its not working at all..
same errors am getting. Please check once my requirements and posted code

Try using case to check in input. Also, OPTARG is a shell built-in, so you might want use a different name.

$ read reply
123-456(

$ case "$reply" in [0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9]) echo good;; *) echo bad;; esac
bad

$ read reply
12345-67890

$ case "$reply" in [0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9]) echo good;; *) echo bad;; esac
good

When you post code, please wrap it in

 tags.



OPTARG=$1

[/quote]

[indent]
It's a bad habit to use variables that the shell uses. OPTARG is used with getopts.

You haven't defined $length.

You don't need '-$cnt', just '-c$cnt'.

In fact, you don't need cut at all. You don't even need the loop.

range=$1
first_field=${range%%-*}
second_field=${range#*-}
case $first_field$second_field in
     *[!0-9]*) echo INVALID; exit 1 ;;
     *) echo OK ;;
esac

Parentheses on the command line mkust be escaped (or quoted). It has nothing to do with your script; echo 3663-929( will give you the same error.