This article introduces three user-defined functions, one date verification, one time verification, and one verification for whether it is time and date. If you need them, refer to Step 5. This article introduces three user-defined functions, one date verification, one time verification, and one verification for whether it is time and date. If you need them, refer to Step 5.
Script ec (2); script
Date verification format 2011-12-12
| The Code is as follows: |
|
Function is_date ($ str)
{
$ YEAR = "";
$ MONTH = "";
$ DAY = "";
$ Len = strlen ($ str );
$ Offset = 0;
$ I = strpos ($ str, "-", $ offset );
$ YEAR = substr ($ str, $ offset, $ I-$ offset );
$ Offset = $ I + 1;
If ($ len <$ offset)
{
Return FALSE;
}
If ($ I)
{
$ I = strpos ($ str, "-", $ offset );
$ MONTH = substr ($ str, $ offset, $ I-$ offset );
$ Offset = $ I + 1;
If ($ len <$ offset)
{
Return FALSE;
}
If ($ I)
{
$ DAY = substr ($ str, $ offset, $ len-$ offset );
}
}
If ($ YEAR = "" | $ MONTH = "" | $ DAY = "")
{
Return FALSE;
}
If (! Checkdate (intval ($ MONTH), intval ($ DAY), intval ($ YEAR )))
{
Return FALSE;
}
Return TRUE;
} |
Time verification Zhao 11:12:32
| The Code is as follows: |
|
Function is_time ($ str)
{
$ TEMP = "";
$ HOUR = "";
$ MIN = "";
$ SEC = "";
$ TEMP = strtok ($ str ,":");
$ HOUR = $ TEMP;
If ($ HOUR = "" | 24 <= $ HOUR | $ HOUR <0 |! Is_number ($ HOUR ))
{
Return FALSE;
}
$ TEMP = strtok (":");
$ MIN = $ TEMP;
If ($ MIN = "" | 60 <= $ MIN | $ MIN <0 |! Is_number ($ MIN ))
{
Return FALSE;
}
$ TEMP = strtok (":");
$ SEC = $ TEMP;
If ($ SEC = "" | 60 <= $ SEC | $ SEC <0 |! Is_number ($ SEC ))
{
Return FALSE;
}
Return TRUE;
} |
Time and date verification: 12:12:12
| The Code is as follows: |
|
|
Function is_date_time ($ DATE_TIME_STR)
{
If ($ DATE_TIME_STR = NULL | strlen ($ DATE_TIME_STR) = 0)
{
Return FALSE;
}
$ DATE_TIME_ARRY = explode ("", $ DATE_TIME_STR );
If (is_date ($ DATE_TIME_ARRY [0]) & is_time ($ DATE_TIME_ARRY [1])
{
Return TRUE;
}
Return FALSE;
} |