tags:

views:

261

answers:

2

With the HTML helper, how would you enforce number only without submitting? I know it was done with regular expression if you had a textbox in classic ASP.NET

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

+1  A: 

If the data type on the model is numeric (int, etc) you can just use an attribute, and turn on client validation. More details here.

Andrew Lewis
Nic thanks! That's what I was looking for.
gmang
A: 

Another option would be to use the jquery Validation Plugin.

This would allow you to just add the class "required digits" and it would do the validation magic for you.

Andrew Cox