【发布时间】:2014-10-31 11:52:33
【问题描述】:
^(0[1-9]|[12][0-9]|3[01])[-\/](0[1-9]|1[012])[-\/](19|20)\d\d$
在 Firefox 33.02 中,10/10/2014 有效,但 10-10-2014 无效。
但是在 chrome 中 10/10/2014 和 10-10-2014 都可以工作。
为什么?
编辑:
我发现不是表达式无效,而可能是 MVC 中的某些东西
型号:
[Required(ErrorMessage = "Field is required")]
[RegularExpression(@"^(0[1-9]|[12][0-9]|3[01])[-\/](0[1-9]|1[012])[-\/](19|20)\d\d$", ErrorMessage = "Date is incorrect")]
[DataType(DataType.Date)]
public DateTime BevBday { get; set; }
cshtml:
@Html.TextBoxFor(model => model.BevBday)
使用这个,在 Firefox 中它会显示为
BevBday 字段必须是日期。
在 chrome 中它不会给出同样的错误。
【问题讨论】:
-
好吧……我现在看到了“c#”标签。所以这是某种服务器代码(asp.net?),它动态生成html/js?这从最初的问题中并不明显。
标签: c# regex asp.net-mvc