Problem with Date validation

Hi All,

I've to validate a date input for the format YYYYMMDD. The input should be of 8 digits with only numeric values.

I tried the following

echo $1 | grep '^[0-9]\{8}$/p'
if [ $? -eq 0 ]
then
 echo "Valid"
else
 echo "invalid" 

I get the error,

grep: RE error 16: Bad number.

Any help will be appreciated.
Thanks,
Sumesh

Couple of mistakes in your script.

\{8} should be \{8\}
What is the \p in grep '^[0-9]\{8}$/p'
You need to close the if construct with a fi

echo $1 | grep '^[0-9]\{8\}$'
if [ $? -eq 0 ] ; then
     echo "Valid"
else
      echo "invalid"
fi

It worked!!Thanks Vino.

Cheers,
Sumesh

Hi Vino,

Can you give the date validation script as per the following requirement:

I want a sample Date validation script using if loops.
The script should first compare "year".If the year is lesser than the current year,It should go for "month" checking.
I have the script that splits the date into year,month and date.I want only the checking part.
My if loop checking is not work properly.
Can you show the right way of checking?

Regards
Dave