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" }) %>

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.