title: onchange event not working in mvc razor page
body: <p>I am adding an email address and a contact no validation but both are not working.</p>
  <p>I enter this email address and then insert it successfully in database:</p>
  <pre><code>asda
  </code></pre>
  <p>I enter this contact no and then insert it successfully in database:</p>
  <pre><code>1234
  </code></pre>
  <p>it gives an alert invalid but issue is when I press the button then successfully insert the database.</p>
  <p>.cshtml</p>
  <pre><code>
  @{
      ViewBag.Title = &quot;Career&quot;;
  }
  
  &lt;h2&gt;Career&lt;/h2&gt;
  
  @using (Html.BeginForm(&quot;Career&quot;, &quot;Home&quot;, FormMethod.Post, new { enctype = &quot;multipart/form-data&quot; }))
  {
      &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-md-12&quot;&gt;
              &lt;h3 style=&quot;text-align:center&quot;&gt;Upload Form&lt;/h3&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-md-2&quot;&gt;
              &lt;label&gt;EmailId:&lt;/label&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-md-4&quot;&gt;
              &lt;input class=&quot;form-control&quot; type=&quot;text&quot; name=&quot;useremailid&quot; placeholder=&quot;Please Enter EmailAddress&quot; onchange=&quot;validateEmail()&quot; required /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;br /&gt;
      &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-md-2&quot;&gt;
              &lt;label&gt;ContactNo:&lt;/label&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-md-4&quot;&gt;
              &lt;input class=&quot;form-control&quot; type=&quot;number&quot; name=&quot;usercontactno&quot; placeholder=&quot;Please Enter ContactNo&quot; onchange=&quot;validateContactNo()&quot; title=&quot;Enter 10 digit mobile number&quot; required /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;br /&gt;
      &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-md-2&quot;&gt;
              &lt;label&gt;Resume:&lt;/label&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-md-4&quot;&gt;
              &lt;input type=&quot;file&quot; name=&quot;userresume&quot; required /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;br /&gt;
      &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-md-2&quot;&gt;
              &lt;input class=&quot;btn bg-success&quot; type=&quot;submit&quot; value=&quot;Create&quot; /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  }
  
  &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js&quot;&gt;&lt;/script&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
  
      function validateEmail() {
          var text = document.getElementsByName(&quot;useremailid&quot;).value;
          var regx = /^([A-Za-z0-9_\-\.])+\@@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
          if (regx.test(text))
              alert(&quot;valid&quot;);
          else
              alert(&quot;invalid&quot;);
      }
  
      function validateContactNo() {
          var text = document.getElementsByName(&quot;usercontactno&quot;).value;
          var regx = /\d{10}/;
  
          if (regx.test(text))
              alert(&quot;valid&quot;);
          else
              alert(&quot;invalid&quot;);
      }
  
  &lt;/script&gt;   
  </code></pre>
  <p><a href="https://i.stack.imgur.com/cd2sP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cd2sP.png" alt="enter image description here" /></a></p>
  <p>After the alert pops up, then press the button, then store the <strong>data(asd emailaddress)</strong> successfully in the database.</p>
  <p>What I am trying:</p>
  <p><strong>I am trying on button click but it's also not working</strong></p>
  <pre><code>&lt;input class=&quot;form-control&quot; type=&quot;text&quot; name=&quot;useremailid&quot; placeholder=&quot;Please Enter EmailAddress&quot;  required /&gt;
  
  &lt;input class=&quot;form-control&quot; type=&quot;number&quot; name=&quot;usercontactno&quot; placeholder=&quot;Please Enter ContactNo&quot; required /&gt;
  
  &lt;input class=&quot;btn bg-success&quot; type=&quot;submit&quot; id=&quot;submit&quot; value=&quot;Create&quot; /&gt;
  
  &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js&quot;&gt;&lt;/script&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
  
      $(document).ready(function () {
          $('#submit').click(function () {
  
                  var emailid = document.getElementsByName(&quot;useremailid&quot;).value;
                  var regx = /^([A-Za-z0-9_\-\.])+\@@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  
              if (emailid) {
                  if (regx.test(text))
                      alert(&quot;valid&quot;);
                  else
                      alert(&quot;invalid&quot;);
              }
  
              var contactno = document.getElementsByName(&quot;usercontactno&quot;).value;
              var regx = /\d{10}/;
  
              if (contactno) {
  
                  if (regx.test(text))
                      alert(&quot;valid&quot;);
                  else
                      alert(&quot;invalid&quot;);
              }
          })
      });
  &lt;/script&gt;
  </code></pre>
  <p><strong>I am trying on submit form but it's also not working</strong></p>
  <pre><code>@using (Html.BeginForm(&quot;Career&quot;, &quot;Home&quot;, FormMethod.Post, new { enctype = &quot;multipart/form-data&quot;, id = &quot;frmsubmit&quot; }))
  {
  
    &lt;input class=&quot;form-control&quot; type=&quot;text&quot; name=&quot;useremailid&quot; placeholder=&quot;Please Enter EmailAddress&quot; required /&gt;
  
  
        &lt;input class=&quot;form-control&quot; type=&quot;number&quot; name=&quot;usercontactno&quot; placeholder=&quot;Please Enter ContactNo&quot; required /&gt;
  
  &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js&quot;&gt;&lt;/script&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
      $(document).ready(function () {
          $('#frmsubmit').submit(function () {
  
              var emailid = document.getElementsByName(&quot;useremailid&quot;).value;
              var regx = /^([A-Za-z0-9_\-\.])+\@@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  
              if (emailid) {
                  if (regx.test(text))
                      alert(&quot;valid&quot;);
                  else
                      alert(&quot;invalid&quot;);
              }
  
              var contactno = document.getElementsByName(&quot;usercontactno&quot;).value;
              var regx = /\d{10}/;
  
              if (contactno) {
  
                  if (regx.test(text))
                      alert(&quot;valid&quot;);
                  else
                      alert(&quot;invalid&quot;);
              }
          })
      });
  &lt;/script&gt;
  </code></pre>