title: Comparing two input values in a form validation with AngularJS
body: <p>I am trying to do a form validation using AngularJS. I am especially interested in comparing two values. I want the user to confirm some data he entered before he continues. Lets say I have the code below:</p>
  
  <pre><code>&lt;p&gt;
      Email:&lt;input type="email" name="email1" ng-model="emailReg"&gt;
      Repeat Email:&lt;input type="email" name="email2" ng-model="emailReg2"&gt;
  &lt;p&gt;
  </code></pre>
  
  <p>and then I can use validation with:</p>
  
  <pre><code>&lt;span ng-show="registerForm.email1.$error.required"&gt;Required!&lt;/span&gt;
  &lt;span ng-show="registerForm.email1.$error.email"&gt;Not valid email!&lt;/span&gt;
  &lt;span ng-show="emailReg !== emailReg2"&gt;Emails have to match!&lt;/span&gt;  &lt;-- see this line
  </code></pre>
  
  <p>registerForm.$valid will react correctly as to the text in inputs except I do not know how to use comparison within this validation to force the emails to be the same before allowing the user to submit the form.</p>
  
  <p>I would love to have a solution without custom directives, but if this can't be achieved without it I will deal with it. <a href="https://stackoverflow.com/questions/12581439/how-to-add-custom-validation-to-an-angular-js-form">Here</a> is an answer that addresses similar issue with a  custom directive.</p>
  
  <p>Any help appreciated, thank you</p>