http://
或https://
或\\
开头。我正在使用System.componentmodel.DataAnnotations.RegularExpressionAttribute。
[Display(Name = "URL", Description = "URL")]
[RegularExpression(@"^(http[s]{0,1}:\/\/|\\\\)",
ErrorMessage = "Please enter valid Url or filepath")]
public string URL { get; set; }
但在数据表单字段中,如果在http://、https://或\\后输入任何文本,则会出现错误。
http://google.com ---failed
https://aa --failed
\\a ----failed
我只希望通过以上所有场景...从高层次上讲,正则表达式应该只检查输入的文本是否以http://
、https://
或\\
开头。
即使用户输入并删除文本,然后点击选项卡,数据表格仍会为该字段抛出错误。错误信息是URL是必填字段,但我没有为此属性指定必填属性。请帮忙。
\\\a
,目前没有正确匹配任何正则表达式模式。 - Tseng