Issue with Laravel Rules & Regex (OR) operator

前端 未结 3 1470
悲哀的现实
悲哀的现实 2020-11-28 15:34

I\'m having a small issue with my Laravel rules and regex operation :

Basically a rule is an array as such :

\'room\'=>\'required|alpha_num|min:2|         


        
3条回答
  •  庸人自扰
    2020-11-28 16:21

    I use this style and save my life :-)

    change code from

        $validator = Validator::make(
        $request->all(),
            [
            'name' => 'required|string',
            'initial_credit' => 'required|integer|between:0,1000000|regex:/[1-9][0-9]*0000$/'
            ]
        ]);
    

    to

        $validator = Validator::make(
        $request->all(),
            [
            'name' => 'required|string',
            'initial_credit' => [ // <=== Convert To Array
                'required',
                'integer',
                'between:0,1000000',
                'regex:/([1-9][0-9]*0000$)|([0])/' // <=== Use pipe | in regex
            ] // <=== End Array
        ]);
    

提交回复
热议问题