我想验证alpha_dash(字母和空格),下面的代码工作正常
Validator::extend('alpha_spaces', function($attribute, $value)
{
return preg_match("/^[a-z0-9 .\-]+$/i", $value);
});
但它给出的错误不是用户友好的:
validation.alpha_spaces
如何更改此消息?
这是帖子的方法
public function create(Request $request)
{
$this->validate($request, [
'title' => 'required|alpha_spaces|max:255',
]);
}
谢谢!
答案 0 :(得分:3)
只需将自定义错误消息作为数组元素添加到resources/lang/xx/validation.php
:
'alpha_spaces' => 'The :attribute may only contain letters, numbers and spaces.',
了解详情:http://laravel.com/docs/5.0/validation#custom-error-messages