Q:

validating number input regex

I am writing a regex for my shell script program that will check 
1) the number should be 8 digit
2) the first number must start from 8 or 9
below is what I have but the regex doesn't seem to make anything happen 
startWithEightOrNineDigitRegex="/^[8-9]/d{8}"
echo "Enter a 8 digit number"
read eightDightNumber
if [[ $eightDightNumber =~ $startWithEightOrNineDigitRegex ]]; then
   echo "Number must start with 8 or 9"
elif [[ $eightDigitNumber -lt 8 ]]
   echo "Number must be in 8 digits "
else
   echo $eightDightNumber
fi

Any suggestions?  thanks in advance

A:

Change the regular expression to '^[89][0-9]{7}$'. 
Beside that, if statement body should be adjusted. 
startWithEightOrNineDigitRegex='^[89][0-9]{7}$'
echo "Enter a 8 digit number"
read eightDightNumber
if [[ "$eightDightNumber" =~ $startWithEightOrNineDigitRegex ]] ; then
   echo $eightDightNumber
else
   echo "Number must start with 8 or 9 and should be in 8 digits"
fi

or negate the expression:
startWithEightOrNineDigitRegex='^[89][0-9]{7}$'
echo "Enter a 8 digit number"
read eightDightNumber
if [[ ! " $eightDightNumber" =~ $startWithEightOrNineDigitRegex ]] ; then
   echo "Number must start with 8 or 9 and should be in 8 digits"
else
   echo $eightDightNumber
fi

