0
votes

I have a trouble with xor validation.
I want to validate with given two input.

For example,

$input1 = true;
$input2 = true;
$result = validateFunction($input1, $input2);
// $result is false

true is allowed only one input. If both of the input is true, I want to restrict.

I thought it can be achieved by function($context){}.
However, notEmpty and allowEmpty are not suitable.
Because one of the input should be empty if $result is false.
And notEmpty and allowEmpty don't force the input empty.

I should make custom validation rule, I think.
Anyone have any idea? Thank you very much.

1

1 Answers

0
votes

If I understand you correctly, do you want to create a simple xor validation? If so just use the ^ operator:

function validateFunction($input1, $input2) {
  return $input1 ^ $input2;
} 

for more information: https://www.php.net/manual/en/language.operators.bitwise.php