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