Hi, I've got a form request, that has a basic requirement.
- It needs valid npa phone numbers.
- It only needs one phone number even though more than one is asked for.
Right now, I can get either to work, but not both
OPTION 1 Works for requiring only one phone.
public function rules()
{
return [
'cell_phone' => 'required_without:home_phone',
'home_phone' => 'required_without:cell_phone',
];
}
OPTION 2 Works for validating an npa phone number
public function rules()
{
return [
'cell_phone' => 'npa_phone',
'home_phone' => 'npa_phone',
];
}
NPA is in AppServiceProvider Boot method:
public function boot()
{
Validator::extend('npa_phone', function($attribute, $value, $parameters)
{
$attribute = preg_replace('/\D/', '', $value);
$pattern = '~^\(?([2-9][0-9]{2})\)?([2-9](?!11)[0-9]{2})([0-9]{4})$~';
return preg_match($pattern, $value);
});
}
What I'm trying to accomplish is the following:
return [
'cell_phone' => 'required_without:home_phone|npa_phone',
'home_phone' => 'required_without:cell_phone|npa_phone',
];
Any advice appreciated.