Consider these lines:
if( any(month == [4,6,9,11]) && day<=30 )
valid = true;
if ( any(month == [1,3,5,7,8,10,12]) && day<=31)
That is, if the month is one of [4,6,9,11] and you passed that first if-test, then how can you ever pass that 2nd if-test which is inside the if-block of the first test? (You can't)
You need to rethink and rework this logic. Step through it one line at a time to see what it is really doing with those incorrect results.