I'm working with ASP.NET MVC 5, jquery 3.1 I have a form in which I have a control input, which I only need to allow me to enter only numbers.
Jquery code
<script>
$('#NumeroDocumento').on('keypress', function (e) {
if (!$.isNumeric(String.fromCharCode(e.which))) {
e.preventDefault();
}
});
View
<div class="form-group">
@Html.LabelFor(model => model.NumeroDocumento, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.NumeroDocumento, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.NumeroDocumento, "", new { @class = "text-danger" })
</div>
</div>
I do not know why it's not working?