Laravel Validation with or

﹥>﹥吖頭↗ 提交于 2021-01-28 02:55:50

问题


I have a laravel validation that needs to match one of the 3 regex's

 $validatedData = $request->validate([

        'BCH-address' => 'regex:/^([13][a-km-zA-HJ-NP-Z1-9]{25,34})/',
        'BCH-address' => 'regex:/^((bitcoincash:)?(q|p)[a-z0-9]{41})/',
        'BCH-address' => 'regex:/^((BITCOINCASH:)?(Q|P)[A-Z0-9]{41})$/',

    ]),

Is there a way to use a OR condition for the validation??


回答1:


You can add rule https://laravel.com/docs/5.6/validation#using-rule-objects and there your logic,
or use closure https://laravel.com/docs/5.6/validation#using-closures
or make it as separate rule https://laravel.com/docs/5.6/validation#using-extensions



来源:https://stackoverflow.com/questions/50644122/laravel-validation-with-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!