title: Client Side Validation before sending data to server ASP.Net MVC
body: <p>I have a view in ASP.Net . I have added some controls in the view. I am trying to do client side validation before sending the data to server. If everything is fine, I want to send it to server.<br>
  <strong>My code is here:</strong></p>
  
  <pre><code>     @using (Html.BeginForm("Index", "staff", FormMethod.Post))
              {
              @Html.AntiForgeryToken()
              @Html.ValidationSummary(true)
  
              &lt;div class="form-group has-feedback"&gt;
                  &lt;div&gt; @Html.LabelFor(a =&gt; a.staff_name, "Staff Name")&lt;/div&gt;
                  @Html.TextBoxFor(a =&gt; a.staff_name, new { @class = "form-control", placeholder = "", required = "required", autofocus = "autofocus"})
              &lt;/div&gt;
                      &lt;div class="form-group has-feedback"&gt;
                          &lt;div&gt; @Html.LabelFor(a =&gt; a.user_name, "Username")&lt;/div&gt;
                          @Html.TextBoxFor(a =&gt; a.user_name, new { @class = "form-control", placeholder = "", required = "required" })
  
                      &lt;/div&gt;
                      &lt;div class="form-group has-feedback"&gt;
                          &lt;div&gt; @Html.LabelFor(a =&gt; a.password, "Password")&lt;/div&gt;
                          @Html.PasswordFor(a =&gt; a.password, new { @class = "form-control", placeholder = "", required = "required",id="password" })
  
                      &lt;/div&gt;
                      &lt;div class="form-group has-feedback"&gt;
                          &lt;div&gt; @Html.LabelFor(a =&gt; a.confirm_password, "Confirm Password")&lt;/div&gt;
                          @Html.PasswordFor(a =&gt; a.confirm_password, new { @class = "form-control", placeholder = "", required = "required", id = "c_password" })
  
                      &lt;/div&gt;
  
                      &lt;div class="row"&gt;
                          &lt;div class="col-xs-3 "&gt;
                              &lt;button type="submit" class="btn btn-primary btn-md pull-right" onsubmit="validateForm()"&gt;Submit&lt;/button&gt;
                          &lt;/div&gt;&lt;!-- /.col --&gt;
                      &lt;/div&gt;
          }
      &lt;/div&gt;
  &lt;/section&gt;
  &lt;script type="text/javascript"&gt;
      function validateForm()
      {
          var pass = document.getElementById("password").value;
          var c_pass = document.getElementById("c_password").value;
  
          if(pass==c_pass)
          {
              //submit
          }
  
      }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>I want to check if 'password' and 'confirm password' matches or not.If yes, then only post in the server.</p>