It would be better to know a) what shell you are running b) where the date comes from c) where it's going.
You could do it with a quick awk script like so
read var
echo $var|awk '{ flag $0 }
{ if ( length($0)!=8){ flag = "INVALID"
{ for ( i = 1;i <= length($0);i++)
if( substr($0,i,1)<0 || substr($0,i,1)>9){flag = "INVALID"}
{print flag}'|pg
If you wanted better date testing ( i.e. valid month, day etc. ) something a bit more complex would need to be written.
There are possibly easier ways to do this, if anyone knows any, I'd be interested too. SOL
The best thing about banging your head against a wall is when you stop.