jeffreychi
jeffreychi

Reputation: 199

mvc Html.TextBoxFor

I have a question here about html.textboxfor

I knew that we can use Html.TextBoxFor to restrict the size of the user input

Html.TextBoxFor(model => model.EmployerNumber, new {size=3})

But can we configure it to take numeric value only ?

I try to get Html.ValidationMessageFor to throw error when input value is not numeric.

Many thanks.

Upvotes: 2

Views: 1351

Answers (1)

Will Ayd
Will Ayd

Reputation: 7164

a textbox accepts text so its not really capable of being limited just to numbers. the best way to do what you want to do is have a model set up that only accepts numeric values and then use client side validation to alert the user that only numeric values are acceptable.

Upvotes: 3

Related Questions