Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-26-2006, 02:05 AM
afullcup afullcup is offline
 
Join Date: Jul 2006
Posts: 63
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default date functions for verifying user input?

I am collecting a date on a form and want it to be entered as MM/DD/YY - what's the best way to verify in my PHP that it is a correct date?

thanks!
Reply With Quote
  #2  
Old 08-26-2006, 07:31 PM
Eric's Avatar
Eric Eric is offline
 
Join Date: May 2006
Location: Kentucky
Posts: 792
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Something i've used:
PHP Code:
/**
* We use this to ensure a valid date is entered
*
* @param  string  Date to be checked.
* @return boolean
*/
function is_valid_date($date)
{
    // Expects mm/dd/yyyy
    // eg: 08/26/2006
    if (preg_match('#[0-9]{2}\/[0-9]{2}\/[0-9]{4}#', $date))
    {
        $date = explode('/', $date);

        // www.php.net/checkdate
        if (checkdate($date[0], $date[1], $date[2]))
        {
            return true;
        }
    }
    return false;
} 
Reply With Quote
  #3  
Old 08-29-2006, 01:10 AM
afullcup afullcup is offline
 
Join Date: Jul 2006
Posts: 63
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks SecondV!! I'll try that!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:31 PM.


Powered by vBulletin® Version 3.9.0
Copyright ©2000 - 2017, vBulletin Solutions Inc.