so i'm Trying to check whether an variable is with the following format YYYY-MM-DDTHH:MM:SS.MSSZ
(ISO8601 timestamp) using preg_match.
What i have tried:
$timezone = new DateTime("now", new DateTimeZone(date_default_timezone_get()));
var_dump(boolval(preg_match("/^[0-9]{4,4}-[0-9]{2,2}-[0-9]{2,2}T[0-9]{2,2}:[0-9]{2,2}:[0-9]{2,2}(Z)|(\+[0-9]{2,2}:[0-9]{2,2})$/", date("Y-m-d\TH:i:s." .round(microtime(True) * 1000). "\\" . $timezone->format('P')))));
but the var_dump always result in invalid results... For example when i use an timestamp with invalid ISO8601 format
Expected result: bool(false)
and Output: bool(true)
so it result in bool(true)
at most of cases...(it doesn't matter if it's invalid or valid).