我想验证laravel中的URL.我的规则包括
"url" => "required|url"
This is working great. But when a user submits an url with umlauts, the rule check will always fail.
像ääää等角色..在德语域中有效.Laravel有没有办法在URL中接受这些字符?
我想验证laravel中的URL.我的规则包括
"url" => "required|url"
This is working great. But when a user submits an url with umlauts, the rule check will always fail.
像ääää等角色..在德语域中有效.Laravel有没有办法在URL中接受这些字符?
Laravel uses filter_var()
with the FILTER_VALIADTE_URL
option which doesn't allow umlauts. You can write a custom validator or use the regex
validation rule in combination with a regular expression. I'm sure you'll find one here
"url" => "required|regex:".$regex
Or better specify the rules as array to avoid problems with special characters:
"url" => array("required", "regex:".$regex)
或者,正如@Michael指出的那样,在验证之前只需替换变音即可.只需确保事后保存真实的:
$input = Input::all();
$validationInput = $input;
$validationInput['url'] = str_replace(['ä','ö','ü'], ['ae','oe','ue'], $validationInput['url']);
$validator = Validator::make(
$validationInput,
$rules
);
if($validator->passes()){
Model::create($input); // don't use the manipulated $validationInput!
}