ASP.NET MVC Html.textbox - How to check only numbers?

With an HTML helper, how would you dial a number just without sending? I know this was done with regex if you had a textbox in classic ASP.NET

<%= Html.TextBox("txtYearOfWork",
                 String.Empty, 
                 new { maxlength = 4, size="5", autocomplete = "off" }) %>

      

+2


source to share


2 answers


If the datatype on the model is numeric (int, etc.), you can simply use the attribute and enable client validation. More details here .



+6


source


Another option is to use jquery validation plugin .



This will allow you to simply add the "required numbers" class and it will do the validation magic for you.

+1


source







All Articles