1

Basically I want the user of my site (ASP.NET MVC 4) to be able to increase his balance (input in a textbox). I know how to do that if the integer was an integer of a model, however how can I do it with just a bare integer.

@Html.TextBox("Deposit")

I want to make sure that when the textbox is submitted, only integers are contained (on client side). How can I do this without making a model of the integer and writing a textbox for the model attribute?

John Mayer
  • 3,313
  • 3
  • 19
  • 20

2 Answers2

0

html5

<input type="number" name="Deposit" min="1" max="5">

Cant test this right now but somthing like this should cover it..

@Html.TextBox(
    "Deposit", 
    null, 
    new { 
        @class = "span1", 
        type = "number", 
        required = "required" 
    }
)
Magnus Karlsson
  • 3,549
  • 3
  • 31
  • 57
0

You can use javascrip/jQuery validation. See this SO question: Simple number validation using JavaScript / jQuery and this: Positive number validation in jquery

Community
  • 1
  • 1
Gichamba
  • 997
  • 12
  • 16