Intervention\Validation\Validator::isIsodate PHP Method

isIsodate() public static method

Checks if given value is date in ISO 8601 format.
public static isIsodate ( mixed $value ) : boolean
$value mixed
return boolean
    public static function isIsodate($value)
    {
        $pattern = '/^([\\+-]?\\d{4}(?!\\d{2}\\b))((-?)((0[1-9]|1[0-2])(\\3([12]\\d|0[1-9]|3[01]))?|W([0-4]\\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\\d|[12]\\d{2}|3([0-5]\\d|6[1-6])))([T\\s]((([01]\\d|2[0-3])((:?)[0-5]\\d)?|24\\:?00)([\\.,]\\d+(?!:))?)?(\\17[0-5]\\d([\\.,]\\d+)?)?([zZ]|([\\+-])([01]\\d|2[0-3]):?([0-5]\\d)?)?)?)?$/';
        return (bool) preg_match($pattern, $value);
    }

Usage Example

 public function testValidateIsodate()
 {
     $iso_dates = array('1977-06-17', '2000-06-17 06:15:12', '1977', '1977-06-17 00:00', '1977-06-17 14:12:59', '2009-05-19 14:39:22+0600');
     foreach ($iso_dates as $date) {
         $this->assertTrue(Validator::isIsodate($date));
     }
     $no_iso_dates = array('17. Juni 1977', '2000-16-37 06:15:12', 'test', '0000-00-00 00:00', '1977-06-17 44:81:99', '2009-05-19 14:39:22+5234');
     foreach ($no_iso_dates as $no_date) {
         $this->assertFalse(Validator::isIsodate($no_date));
     }
 }