开发者

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) %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜