ksh case statement

I am trying to write a ksh script using the case statement to select certain directories to remove. The directories that I am looking for are in the following format 2008-10-10. I want to exclude all other files/directories that contain anything other the 4 digit year,a dash, 2 digit month, a dash and 2 digit day. I tried the following but it did not work.

case $i in
*[A-Z|a-z|.])
break
;;
*[0-9]|[-]
)
echo "i is " $i
;;
esac

case $i in
     [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]) echo "i is $i" ;;
     *) break;;
esac

You can try testing your date with something like this:


$  grep --version
grep (GNU grep) 2.5.1


$ echo '2008-10-10' | grep -Eq '^20[0-9]{2}-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2][0-9]|3[0-1])$'

$ echo $?
0

$ echo '2008-12-16' | grep -Eq '^20[0-9]{2}-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2][0-9]|3[0-1])$'

$ echo $?
0

$ echo '2008-10-99' | grep -Eq '^20[0-9]{2}-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2][0-9]|3[0-1])$'

$ echo $?
1

$echo 'Hello World'  | grep -Eq '^20[0-9]{2}-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2][0-9]|3[0-1])$'

$ echo $?
1

This regex also check for valid dates as best it can. Meaning, it doesn't check for leap year or stuff like 2008-02-31. To do that, I would suggest you write a more sophisitcated function for that. But this one-liner will be sufficient for most of the stuff you want.

$ echo '2008-92-10' | grep -Eq '^20[0-9]{2}-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2][0-9]|3[0-1])$'

$ echo $?
1

$ echo '20081216' | grep -Eq '^20[0-9]{2}-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2][0-9]|3[0-1])$'

$ echo $?
1