Validate only alphanumeric characters in Laravel

后端 未结 4 575
野的像风
野的像风 2021-02-08 17:26

I have the following code in my Laravel 5 app:

public function store(Request $request){
    $this->validate($request,          


        
4条回答
  •  不思量自难忘°
    2021-02-08 18:17

    You forgot to quantify the regex, it also wasn't quite properly formed.

    public function store(Request $request){
        $this->validate($request, ['filename' => 'regex:/^[a-zA-Z0-9_\-]*$/']);
    }
    

    This will accept empty filenames; if you want to accept non-empty only change the * to +.

提交回复
热议问题