validate two fields shouldn't equal to each other yii2
<p>i have a form where i can create football match. there are 3 fields <code>home team</code> (drop down list, where user selects a team), <code>away team</code>(also drop down list) and score field. so <code>&lt;option&gt;</code> tag value equals <code>team_id</code>.
<a href="https://i.stack.imgur.com/xnLm0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xnLm0.png" alt="printscreen"></a></p>

<p>for example, i can choose home team <code>juventus</code>, away team <code>milan</code> and score <code>2:2</code>. problem is, i should validate if home team not equals to away team, so user shouldn't create football match team against itself, for example <code>juventus</code> vs <code>juventus</code>. how should i validate these fields(home_team, away_team) not equal to each other?  </p>

<p>rules method</p>

<pre><code> public function rules()
 {
    return [
        [['score'], 'required'],
        ['home_team_id', 'required', 'message' =&gt; 'Please choose a home team'],
        ['away_team_id', 'required', 'message' =&gt; 'Please choose a away team'],
        ['score', 'match', 'pattern' =&gt; '/^\d{1,2}(:\d{1,2})?$/'],
        ['home_team_id', 'compare', 'compareValue' =&gt; 'away_team_id', 'operator' =&gt; '!=', 'message' =&gt; 'Please choose a different teams'],
        [['away_team_id'], 'exist', 'skipOnError' =&gt; true, 'targetClass' =&gt; Team::className(), 'targetAttribute' =&gt; ['away_team_id' =&gt; 'id']],
        [['home_team_id'], 'exist', 'skipOnError' =&gt; true, 'targetClass' =&gt; Team::className(), 'targetAttribute' =&gt; ['home_team_id' =&gt; 'id']],
        [['round_id'], 'exist', 'skipOnError' =&gt; true, 'targetClass' =&gt; Round::className(), 'targetAttribute' =&gt; ['round_id' =&gt; 'id']],
    ];
  }
</code></pre>

<p>my form</p>

<pre><code>&lt;?php $form = ActiveForm::begin(); ?&gt;

&lt;?= $form-&gt;field($model, 'home_team_id')-&gt;dropDownList($items, $params)-&gt;label('Home Team');?&gt;

&lt;?= $form-&gt;field($model, 'away_team_id')-&gt;dropDownList($items, $params)-&gt;label('Away Team');?&gt;

&lt;div class="hidden"&gt;
    &lt;?= $form-&gt;field($model, 'round_id')-&gt;hiddenInput()-&gt;label(''); ?&gt;
&lt;/div&gt;

&lt;?= $form-&gt;field($model, 'score')-&gt;textInput([
    'maxlength' =&gt; true,
    'placeholder' =&gt; 'seperate goals with colon, for example 2:1'
]) ?&gt;

&lt;div class="form-group"&gt;
    &lt;?= Html::submitButton($model-&gt;isNewRecord ? 'Create' : 'Update', ['class' =&gt; $model-&gt;isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?&gt;
&lt;/div&gt;

&lt;?php ActiveForm::end(); ?&gt;
</code></pre>

<p><code>$items</code> array contains teams(names and ids)</p>