I have 2 field say var1 and var2. both are text fields what I want if var2 contains a word __tocken_ then field var1 is required.
I tried this but it is not working,
$validator = Validator::make(
['var1' => 'required_if:var2,regex:/__tocken_/']
//['var2' => ['required', 'regex:/__tocken_/']] //<--Regex is working fine here
);
So what I'm doing right now I'm setting a 3rd variable var3 and on form submit I'm doing a JS validation if var2 contains a word with pattern __tocken_ then I'm setting var3 as 1 otherwise 0. And the validation rule is
$validator = Validator::make(
['var1' => 'required_if:var3,1'] //working fine
);
So my question is it possible to have regex NOT the exact value in required_if validation rule?
Sample possible value for var2
- Hi
__FIRST_NAME__, lorem ispam__tocken_Ur1vG6xK__. - lorem ispam
__tocken_456vG6xK__lorem__tocken_T57kq6xK__ - lorem ispam.. so on