title: How to validate the form using if condition with multiple errors in Angularjs?
body: <p>I have a scenario,I have to validate the form on click of submit button,but I have a function with multiple error messages in a function using if condition.I have to display the respective error message below sign-in button.</p>
  
  <p>HTML:</p>
  
  <pre><code>  &lt;form name="frmSignIn"&gt;
           &lt;div class="fginpt"&gt;
          &lt;div class="input-group grpsdn"&gt;
     &lt;div class="input-group-addon fginptg"&gt;&lt;img src="images/rgemail.png" /&gt; &lt;/div&gt;
     &lt;input type="text" name="email" class="form-control sgfrmcntr" ng-model="signinCtrlAs.email" placeholder="{{signinCtrlAs.EmailPlaceholder}}" ng-required="true" ng-keypress="signinCtrlAs.keyPress()" ng-blur="signinCtrlAs.emailCheck()"  ng-pattern="signinCtrlAs.emailRegexs" ng-class="{ 'eror' : frmSignIn.email.$invalid &amp;&amp; frmSignIn.email.$touched}" /&gt;
      &lt;/div&gt;
     &lt;p  class="vlderr" ng-if="frmSignIn.email.$invalid &amp;&amp; frmSignIn.email.$dirty"&gt;{{signinCtrlAs.errorEmailMsg }}&lt;/p&gt;
      &lt;/div&gt;
      &lt;div class="fginpt"&gt;
       &lt;div class="input-group grpsdn"&gt;
     &lt;div class="fginptrd input-group-addon fginptg"&gt;&lt;img src="images/rpswrd.png" /&gt; &lt;/div&gt;
      &lt;input type="Password" name="password" class="form-control sgfrmcntr" ng-model="signinCtrlAs.password" placeholder="{{signinCtrlAs.PwdPlaceholder}}" ng-required="true"  ng-keypress="signinCtrlAs.PwdKeyPress()" ng-blur="signinCtrlAs.pwdCheck()"  ng-pattern="signinCtrlAs.pwdRegexs" ng-minlength="8" ng-maxlength="16" ng-class="{ 'eror' : frmSignIn.password.$invalid &amp;&amp; frmSignIn.password.$touched}" &gt;
      &lt;div class="input-group-addon fginptg"&gt;&lt;img src="images/hde-pswrd.png" /&gt; &lt;/div&gt;
         &lt;/div&gt;
    &lt;p class="vlderr" ng-if="frmSignIn.password.$invalid &amp;&amp; frmSignIn.password.$dirty"&gt;{{signinCtrlAs.errorPwdMsg }}&lt;/p&gt;
        &lt;/div&gt;
  
      &lt;div&gt;
    &lt;button   ng-disabled="frmSignIn.email.$invalid || frmSignIn.password.$invalid"  ng-class="{'sgninbtn':frmSignIn.$invalid, 'sgnbtnActv':frmSignIn.$valid}" novalidate  ng-submit="frmSignIn.$valid &amp;&amp; signinCtrlAs.SignIn()" &gt;Sign In&lt;/button&gt;
      &lt;p class="vlderr" ng-show="frmSignIn.$valid.$error.errMsg1"&gt;{{signinCtrlAs.errMsg1 }}&lt;/p&gt;
  &lt;a href="/forgotpwd.html" class="sgnfpsw"&gt;I forgot password&lt;/a&gt;
     &lt;/div&gt;
  
    &lt;/form&gt;
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code> vm.SignIn = function () {
  
      if ($scope.frmSignIn.$valid) {
  
          //SignIn Service Called
  
  
          signinSrvc.signInMember(vm.email, vm.password, function (response) {
            alert(response);
              if (response == 1)
                  //vm.errMsg("", null, 'This is not a registered email', null, "bgWht", 'Password');
                  vm.errMsg1 = "This is not a registered email";
              else if (response == 2)
                  //vm.errMsg("", null, 'This is not a registered email', null, "bgWht", 'Password');
                  vm.errMsg2 = "This is not a registered email";
              else if (response == 3) //or deleted
                  //alert("Your account has been suspended. Please contact our helpdesk for further information");
                  vm.errMsg3 = "Your account has been suspended. Please contact our helpdesk for further information";
                  //vm.errMsg = false;
              else if (response == 4)
                  //vm.errMsg("", null, 'Please sign in with your social network', null, "bgWht", 'Password');
                  vm.errMsg4 = "Please sign in with your social network";
              else if (response == 5)
                  //vm.errMsg("", null, 'Please sign in with your social network', null, "bgWht", 'Password');
                  vm.errMsg5 = "Please sign in with your social network";
              else if (response == 6)
                  //vm.errMsg(vm.Kpcls, vm.email, vm.EmailPlaceholder, null, "", 'Incorrect password - please try again');
                  vm.errMsg6 = "Incorrect password";
              else if (isNaN(response)) {
                  var loginType = $window.sessionStorage.getItem("loginType");
                  if (loginType == "DT") {                        
                      getSessionSrvc.setLoginData(response);
                      $('#signinCmtPop').modal('hide');                       
                  }
                  else {
                      $window.sessionStorage.removeItem("loginType");
                      getSessionSrvc.setLoginData(response);
                      $window.location.href = "/dashboard.html";
                  }
              }
          });
  </code></pre>
  
  <p>Here I have to display the error messages based on response, on click of signin button.</p>