Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save abdullahpazarbasi/817f28cf5c563690d0fb84e4e435f059 to your computer and use it in GitHub Desktop.
Save abdullahpazarbasi/817f28cf5c563690d0fb84e4e435f059 to your computer and use it in GitHub Desktop.
ISO Date-Time Format Regular Expression
<?php
$sPattern = '/^((((19|[2-9]\d)\d{2})\-(0[13578]|1[02])\-(0[1-9]|[12]\d|3[01]))|(((19|[2-9]\d)\d{2})\-(0[13456789]|1[012])\-(0[1-9]|[12]\d|30))|(((19|[2-9]\d)\d{2})\-02\-(0[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))\-02\-29)) ([01]\d|2[0-3]):([0-4]\d|5[0-9]):([0-4]\d|5[0-9]) [+-](0\d|1[0-2]):(00|30)$/';
//
$sSubject = '2020-02-29 23:59:59 +03:00';
//
if (!preg_match($sPattern, $sSubject)) {
echo 'oops!';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment