Created
March 24, 2016 19:54
-
-
Save willemwollebrants/e50813819ad9cc52168c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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