I have a form that the user can enter several fields. Two of these fields are Start Date (date) and Closed Date (closed). date is a required field and is validated using ereg without any problems. closed is optional and thats where my problem lies. I am basically trying to embed an if else statement within an if statement. I have tried this every possible way I can think yet I am having no luck. It eatheir gives me the "wrong format" error if the date is left blank or accepts any format at all. Here is a snippet of the code I am using. All variables are defined in a form on the previous page:
if ($closed!="") $checkdate="true";
else $checkdate="false";
if($checkdate="true"){
if(ereg('[0-9]{2}\/[0-9]{2}\/[0-9]{4}',$date));
else{header("Location:http://givenhost/baddate.html");exit;} }
I basically want it to check to see if $closed got populated and if it did I want it to check and make sure that it is in the MM/DD/YYY format. I realize this is probably available somewhere on the internet or in a manual but I have not been able to find it. Perhaps my mind is just fried from staring at this for so log. If anyone could possibly offer up a suggestion or, better yet, a solution I would be eternally grateful. I sincerely apologize if this is some sort of frequently asked question. Thanks.