Re: checking user input of MM-DD-YYYY

From: Date: Tue, 15 Jan 2008 14:42:49 +0000
Subject: Re: checking user input of MM-DD-YYYY
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-267288@lists.php.net to get a copy of this message
I'm having users enter dates in MM-DD-YYYY format. is there a way to check if what they have entered is invalid (like if they enter 1-15-2008 instead of 01-15-2008) ?
Something like this: http://www.phpguru.org/date_preg/ <?php
    // Get this from where ever (format MM-DD-YYYY)
    echo ($input  = '01-02-2008') . '<br /><br />';
    $result = preg_match('/(\d{2})-(\d{2})-(\d{4})/', $input, $matches);
    $date  = $matches[2]; // Note month/date switched
    $month = $matches[1]; // Note month/date switched
    $year  = $matches[3];
    if (!$result) {
        // Doesn't match...
    }
    echo "Date: {$date}<br />";
    echo "Month: {$month}<br />";
    echo "Year: {$year}<br />";
?> -- Richard Heyes http://www.websupportsolutions.co.uk Mailing list management service allowing you to reach your Customers and increase your sales. ** NOW OFFERING FREE ACCOUNTS TO CHARITIES AND NON-PROFITS **

« previous php.general (#267288) next »