title: form validation in asp.net mvc ( using javascript )
body: <p>i'm new to asp.net mvc and i have aform with some validation and i want to validate it in client side so i write normal script in javascript 
  to be more specefic my problem was the return false ( as it shouldn't send any data to server and still in apage but this doesn't happen) ,note : i test the script in normal html file with js and works fine 
  but as i said i'm not familiar with mvc so i want to know if there any thing i have missed to work in it and if there any reference to any toturial in this specefic point it would be good , as i noticed in this place ( there's no place for beginners :); 
  this is a snippet of my code too </p>
  
  <pre><code>@model registerationex.Models.register
  
  @{
      ViewBag.Title = "Create";
  }
  
  
  &lt;h2&gt;Create&lt;/h2&gt;
  
  @using (Html.BeginForm()) {
      @Html.ValidationSummary(false)
  
      &lt;fieldset&gt;
          &lt;legend&gt;register&lt;/legend&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.name)
          &lt;/div&gt;
  
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.name)
              &lt;span id="error"&gt;&lt;/span&gt;
              @Html.ValidationMessageFor(model =&gt; model.name)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.email)
          &lt;/div&gt;
  
          &lt;div class="editor-field"&gt;
  &lt;input class="text-box single-line" data-val="true" data-val-required="The email field is required." id="email" name="email" type="text" value="" onblur="checkuser(email);"&gt;      
                    &lt;span id="erroruser"&gt;&lt;/span&gt;
              @Html.ValidationMessageFor(model =&gt; model.email)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.age)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.age)
              &lt;span id="errorage"&gt;&lt;/span&gt;
              @Html.ValidationMessageFor(model =&gt; model.age)
          &lt;/div&gt;
  
          &lt;p&gt;
              &lt;input type="submit" value="Create" onclick="allvalidate();"  /&gt;
          &lt;/p&gt;
      &lt;/fieldset&gt;
  }
  
  &lt;div&gt;
      @Html.ActionLink("Back to List", "Index")
  &lt;/div&gt;
  
  
  
  @section Scripts {
      @Scripts.Render("~/bundles/jqueryval")
  
  }
  
  &lt;script&gt;
      function allvalidate() {
          var validated = true;
          if (!validate()) validated = false;
          if (!checkAge(age)) validated = false;
          if (!checkuser(email)) validated = false;
  
          return validated;
      }
  
  
      function validate() {
          var txtf = document.getElementById('name');
          if (txtf.value == 0 || txtf.value == null) {
              document.getElementById('error').innerText = ('you must enter firstname');
              document.getElementById('error').style.color = 'red';
  
              txtf.focus();
              return false;
          }
          else {
              document.getElementById('error').innerText = ('');
              return true;
          }
      }
  
  
      function checkAge(input) {
          if (input.value &lt; 18 || input.value &gt; 70) {
              document.getElementById('errorage').innerText = ('age must be from 18 :70');
              document.getElementById('errorage').style.color = 'red';
              return false;
          }
          else {
              document.getElementById('errorage').innerText = ('');
              return true;
          }
  
      }
  
  
      function checkuser(input) {
          var pattern = '^[a-zA-Z]+$';
          if (input.value.match(pattern)) {
              document.getElementById('erroruser').innerText = '';
              return true;
          }
          else {
              document.getElementById('erroruser').innerText = ('enter valid email');
              document.getElementById('erroruser').style.color = 'red';
  
              return false;
          }
  
  
      }
  
  
  
  &lt;/script&gt;
  </code></pre>