Skip to content

Instantly share code, notes, and snippets.

@willemwollebrants
Created March 24, 2016 19:54
Show Gist options
  • Save willemwollebrants/e50813819ad9cc52168c to your computer and use it in GitHub Desktop.
Save willemwollebrants/e50813819ad9cc52168c to your computer and use it in GitHub Desktop.
<?php
use Valitron\Validator;
$data = ['contact_number' => '', 'email_id' => ''];
//add data with the keys you want to check
$data['contact_info'] = [
'contact_number', 'email_id'
];
Validator::addRule('contact_info_rule', function($field, $value, array $params, array $fields) {
// check if at least one of the fields is not empty
foreach ($value as $field_id) {
if (!empty($fields[$field_id])) {
return true;
}
}
return false;
}, 'One of contact_number, email_id is required');
$validator = new Validator($data);
$validator->rule('contact_info_rule', 'contact_info');
var_dump($validator->validate());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment