c# - ASP.NET 数据注释正则表达式 : Don't allow following characters in Name:\,/, :, *, ;,

标签 c# asp.net-mvc data-annotations

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

[Required]
public string Name { get; set; }

最佳答案

由于这个线程上的人们提出了很好的建议,我最终得到了这个解决方案:

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

关于c# - ASP.NET 数据注释正则表达式 : Don't allow following characters in Name:\,/, :, *, ;,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23487634/

相关文章:

c# - 复制 .svn 文件?

c# - 在 C# 中裁剪图像空白

c# - 返回 linq 结果作为 2D 数组?

c# - 如何在 native C++ 程序中托管 WCF 服务

jquery - 使用 JQuery 在 ASP.Net MVC 中加载部分 View - 首选哪种方法?

asp.net-mvc - 配置ELMAH : Unrecognized config section error

.net - ApplicationInsights 遥测可以帮助诊断高 CPU 使用率问题吗?

c# - Validator 未识别 RegularExpression 数据注释

c# - 我可以创建一个用于属性参数的常量表达式吗?

c# - 当两个类之间存在多个不同(一对多、多对多)关系时如何注释模型类