Here's a function that extracts each element in the string into day, month, year, then uses PHP's checkdate() function to validate (It's set for mm/dd/yy, but you can easily modify for your purpose of dd/mm/yy:
CHECK IF DATE IS VALID
/ check if a date in the format "MM/DD/YYYY" is valid.
returns "Y" if valid, "N" if invalid /
function isValidDateVip($value) {
$strData = strtok($value, "/");
$intCount = 1;
while ($strData) {
if ($intCount == 1) {
$tmpmonth = $strData;
}
if ($intCount == 2) {
$tmpday = $strData;
}
if ($intCount == 3) {
$tmpyear = $strData;
}
$intCount = $intCount + 1;
$strData = strtok("/");
} // while()
if (checkdate($tmpmonth,$tmpday,$tmpyear)) {
return "Y";
} else {
return "N";
}
}
/ sample use: /
$mydate = "2/29/2001";
if (isValidDateVip($mydate) == "Y") {
//is valid
} else {
//is invalid
}
*/
Chris Bulmer wrote:
Anyone have any experience with date validation?
I want to accept a date like this: dd/mm/yy (including the slashes) making sure that the user enters a date later than the current date. I can cobble something together but it\'s not too smart.....
Thanks for any help.
Chris