ASP.NET数据注释正则表达式:不允许在Name:\,/,:,*,;中包含以下字符:

Ass*_*n87 2 c# asp.net-mvc data-annotations

正如标题所说,我正在寻找一个不允许用户使用字符提交名称的正则表达式:(冒号),; (分号),/(正斜杠),\(反斜杠),*(星号)和.(点)

[Required]
public string Name { get; set; }
Run Code Online (Sandbox Code Playgroud)

Ass*_*n87 7

我终于得到了这个解决方案,感谢人们在这个帖子上提出的很好的建议:

[Required]
[RegularExpression(@"^[^\\/:*;\.\)\(]+$", ErrorMessage = "The characters ':', '.' ';', '*', '/' and '\' are not allowed")]
public string Name { get; set; }
Run Code Online (Sandbox Code Playgroud)