开发者

StringLength Mvc

开发者 https://www.devze.com 2023-04-07 03:38 出处:网络
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 h

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

精彩评论

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