Funktion checkDatum() aktualisiert

This commit is contained in:
manu
2021-03-25 15:45:09 +01:00
parent a00009e49f
commit 3359e2e972
+13 -30
View File
@@ -147,51 +147,34 @@ class datum
return false;
}
/**
* Prueft ob das Datum im Format dd.mm.YYYY oder YYYY-mm-dd ist
* @return true wenn ok, false wenn falsches Format
*/
// public function checkDatum($datum)
// {
// if(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})$",$datum) || mb_ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})$",$datum))
// return true;
// else
// return false;
// }
/**
* Prueft ob das Datum im Format dd.mm.YYYY oder YYYY-mm-dd ist UND ob es sich um ein gültiges Datum handelt
* @return true wenn ok, false wenn falsches Format und/oder nicht gültig
*/
public function checkDatum($datum)
{
//Format 12.03.2004
if(mb_ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})$",$datum))
{
//Format dd.mm.yyyy
if(mb_ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})$", $datum))
{
$year=substr($datum,6,4);
$month=substr($datum,3,2);
$day=substr($datum, 0,2);
$year = substr($datum, 6, 4);
$month = substr($datum, 3, 2);
$day = substr($datum, 0, 2);
}
//Format 2012-12-04
elseif(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})$",$datum))
//Format yyyy-mm-dd
elseif(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})$", $datum))
{
$year=substr($datum,0,4);
$month=substr($datum,5,2);
$day=substr($datum,8,2);
$year = substr($datum, 0, 4);
$month = substr($datum, 5, 2);
$day = substr($datum, 8, 2);
}
else
else
{
return false;
}
return checkdate($month, $day, $year);
return checkdate($month, $day, $year);
}