Here’s a nifty little script I use to validate date input with PHP. This function can accept any common date entry and return true if the date is valid or false otherwise.
The Script
function isValidDate ($dateString) {
$x = strtotime ($dateString);
if ($x === false || $x == -1) {
return false;
} else {
return true;
}
}
/* usage */
isValidDate ("March 18, 1977"); // returns true
isValidDate ("tomorrow"); // returns true
isValidDate ("+1 Month"); // returns true
isValidDate ("Invalid Date Here"); // returns false;
?>
Since this isValidDate uses PHP’s strtotime function, it can practically accept any English textual datetime description.
Related Posts
Tags: PHP Programming









Leave a Reply