title: How to assign only numbers to text box in MVC view
body: <p>I have put a text box where i want only numbers. I want to validate it in the client side and written the following code</p>
  
  <pre><code>@using (Html.BeginForm("LoyaltyPoints","Cart",FormMethod.Post))
  {
  &lt;label&gt;Enter point:&lt;/label&gt;
  &lt;br /&gt;
  @Html.TextBoxFor(m =&gt; m.txtLoyaltyPoints, new { @onkeypress = "OnlyNumeric(this)" })
  &lt;br /&gt;
  &lt;input type="submit" value="Submit" /&gt;
  &lt;br /&gt;
  @ViewBag.LoyaltyPointsErrorMessage
  }
  
  @Scripts.Render("~/bundles/jquery")
  &lt;script type="text/javascript"&gt;
  function OnlyNumeric(e) {
      if ((e.which &lt; 48 || e.which &gt; 57)) {
          if (e.which == 8 || e.which == 46 || e.which == 0) {
              return true;
          }
          else {
              return false;
          }
      }
  }
  </code></pre>
  
  <p></p>
  
  <p>now here my javascript is not firing. i tried keeping alert here but not working as intended. What could be the error. please help.</p>