[英]Don't allow special characters with DataAnnotations
I have a string property in my ViewModel and I want to set that to don't allow some special characters as, :, *,?, ", <, > and |. How can I write a regular expression to do it?我的 ViewModel 中有一个字符串属性,我想将其设置为不允许某些特殊字符,如:、*、?、"、<、> 和 |。我该如何编写正则表达式来做到这一点?
Coul be correct [RegularExpression(@"^[^\/: <>?|;.)(]+$")]*?可能是正确的[RegularExpression(@"^[^\/: <>?|;.)(]+$")]*?
There's a problem, what some special symbols are.有一个问题,一些特殊符号是什么。 If the complete list is如果完整列表是
, :, *,?, ", <, > and |
then you can put it as那么你可以把它作为
[RegularExpression(@"^[^,:*?""<>\|]*$")]
if, however, you want to exclude all punctuation ( , :, *, ?, "
) and math symbols ( <, >, |
), you can put但是,如果您想排除所有标点符号( , :, *, ?, "
) 和数学符号 ( <, >, |
),您可以将
[RegularExpression(@"^[^\p{P}\p{Sm}]*$")]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.