Validate a text with jquery

0

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?

    
asked by Pedro Ávila 19.01.2017 в 21:09
source

1 answer

1

I already solved it, I still had to modify a line of code.

<script src="~/scripts/jquery-3.1.1.min.js"></script>
    
answered by 19.01.2017 в 21:33