简体   繁体   English

正则表达式禁止 C# 中的特殊字符

[英]Regex expression to disallow special character in C#

I know this is not the right question to ask, but I have tried many regex and none of them is working.我知道这不是正确的问题,但我尝试了很多正则表达式,但没有一个有效。 I want to exclude special character but need to include only {,},-,:我想排除特殊字符但只需要包含{,},-,:

I need to exclude ?~@#$%`^<>我需要排除?~@#$%`^<>

The request is as below:请求如下:

{  
"StoreNumber":"9907<>",
"AssociateId":"tkmadoy",
"PrchgType":"PCY",
"Header":{  
   "ApiVersion":"18.1.0.0",
  "JsonWebToken":null
}
}

On json parsing I get the below request:在 json 解析时,我得到以下请求:

[{"AssociateId":"tkmadoy","StoreNumber":"9907","Header":{"ApiVersion":"18.1.0.0","JsonWebToken":null,"AppVersion":null},"AllowedSLAMilliSeconds":0,"SLARequestKey":null,"PrchgType":1,"PriceChangeEventType":0}]

but still the regex doesnt work that can omit special character except some.但是正则表达式仍然不起作用,可以省略除某些字符之外的特殊字符。 I created the below for not allowing html tag and special tag for this.我创建了以下内容以不允许为此使用 html 标签和特殊标签。

[^!*()\|\'?~@#$%`^<>]+$

But none of them is working.但他们都没有工作。 I would really appreciate if someone can help me with this.如果有人能帮我解决这个问题,我将不胜感激。

我认为如果不是所有这些字符,你需要逃避大多数。

 [^\?~@#\$%`\^<>]+

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM