StringLength Mvc
As you know there is a property called [StringLength]
in model of mvc. I have a variable which is an int
and I want to restrict it to maximum 4 characters. I need something like [IntLength]
. Can you help me?
[Display(Name="Credit card number:")]
[RegularExpression(@"\d{4}")开发者_C百科]
public int BookingCardNumberFirstFour { get; set; }
<%: Html.TextBoxFor(model => model.BookingCardNumberFirstFour, new {style="width:40px;"}) %>
You can use the range attribute.
[Range(0,9999)]
public int myInt { get; set;}
if you want them to enter exactly 4 digits use the regular expression attribute.
[RegularExpression(@"\d{4}")]
public int myInt {get; set;}
<%: Html.EditorFor(model => model.BookingCardNumberFirstFour, new {style="width:40px;"}) %>
<%: Html.ValidationMessageFor(model => model.BookingCardNumberFirstFour) %>
精彩评论