title: Performing Client Side validation
body: <p>I would like to know what is the best approach to handle client-side, javascript or jQuery driven validation of MVC4 fields against attributes placed on a ViewModel's fields.</p>
  
  <p>here is example</p>
  
  <pre><code>    [Required]
       public string Username { get; set; }
  
       [Required]
       public string Email { get; set; }
  
      &lt;div&gt;
          @Html.LabelFor(m=&gt;m.Username)
          @Html.ValidationMessageFor(m =&gt; m.Username)
      &lt;/div&gt;
  
      &lt;div&gt;
          @Html.LabelFor(m=&gt;m.Email)
          @Html.ValidationMessageFor(m =&gt; m.Email)
      &lt;/div&gt;
  </code></pre>
  
  <p>currently, If I enter an invalid email address, an empty UserName, etc. in the form and hit Submit I'm correctly notified of the errors. it is working as expected</p>
  
  <p>I would like that every time when user lost the focus from text box and on key press, validation for that field must occurs.</p>
  
  <p>I fixed this problem by adding this to every page..</p>
  
  <pre><code>&lt;script&gt;
      $("input").blur(function () {
          $(this).valid();
      });
      $("input").keydown(function () {
          $(this).valid();
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Writing hard-coded jQuery fragments is not the best option. I would like a data-driven approach, possibly embedded in MVC4 or if there is a way to configure jquery.validate.unobtrusive to perform this validation.</p>
  
  <p>waiting for reply,</p>
  
  <p>Thanks-
  Atul</p>