= $minLen; } public static function date($date, string $format = 'Y-m-d'): bool { try{ $d = \DateTime::createFromFormat($format, (string)$date); return $d && $d->format($format) === (string)$date; }catch(\Throwable $e){ error_log($e->getMessage()); return false; } } public static function json($val): bool{ if(!is_string($val) || $val === ''){ return false; } try{ json_decode($val, true, 512, JSON_THROW_ON_ERROR); return true; }catch(\JsonException $e){ error_log($e->getMessage()); return false; } } public static function email($val): bool{ $val = trim((string)$val); if(preg_match("/[\r\n]/", $val)){ return false; } return (bool) filter_var($val, FILTER_VALIDATE_EMAIL); } public static function domain($val): bool{ $val = trim((string)$val); if(preg_match("/[\r\n]/", $val)){ return false; } return (bool) filter_var($val, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME); } public static function minLen($val, int $min): bool{ return mb_strlen(trim((string)$val)) >= $min; } public static function maxLen($val, int $max): bool{ return mb_strlen(trim((string)$val)) <= $max; } public static function regex($val, string $pattern): bool{ return (bool) preg_match($pattern, (string)$val); } }