📜  laravel 自定义验证检查 URL 是否有效 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:57.650000             🧑  作者: Mango

代码示例1
I have created a custom Validator like:

Validator::extend('german_url', function($attribute, $value, $parameters)  {
  $url = str_replace(["ä","ö","ü"], ["ae", "oe", "ue"], $value);
  return filter_var($url, FILTER_VALIDATE_URL);
});

My rules contain now:
"url" => "required|german_url,

Also don't forget to add the rule to your validation.php file
"german_url" => ":attribute is not a valid URL",