code snippet: isDate() mm/dd/yyyy

Include file is found in this directory of the website:


Usage Example

if ( strlen($dateOfPurchase) > 0 and !isDate($dateOfPurchase) ) { $isAnomaly = true; }

Date Format:


Code For isDate Function:

function isDate($i_sDate) {
function isDate
boolean isDate(string)
Summary: checks if a date is formatted correctly: mm/dd/yyyy (US English)
Author: Laurence Veale (modified by Sameh Labib)
Date: 07/30/2001

  $blnValid = TRUE;
  if ( $i_sDate == "00/00/0000" ) { return $blnValid; }
  // check the format first (may not be necessary as we use checkdate() below)
  if(!ereg ("^[0-9]{2}/[0-9]{2}/[0-9]{4}$", $i_sDate)) {
    $blnValid = FALSE;
  } else {
    //format is okay, check that days, months, years are okay
    $arrDate = explode("/", $i_sDate); // break up date by slash
    $intMonth = $arrDate[0];
    $intDay = $arrDate[1];
    $intYear = $arrDate[2];
    $intIsDate = checkdate($intMonth, $intDay, $intYear);
    if(!$intIsDate) {
      $blnValid = FALSE;
  }//end else
  return ($blnValid);
} //end function isDate

About samehramzylabib

See About on
This entry was posted in PHP Code Snippets, PHP Data Value Types, PHP Form Processing, PHP Time Functions and tagged , , , . Bookmark the permalink.


Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s