简体   繁体   English

C#正则表达式,用于空格,字母数字和特殊字符的组合

[英]C# Regular expression for combination of space, alphanumeric and special characters

I am using asp.net 3.5 with C# 2008. 我在C#2008中使用asp.net 3.5。

I have a textbox and to validate it I have a regular expression validator. 我有一个文本框,要验证它,我有一个正则表达式验证器。 For allowing Alpha-numerics, space and certain special character I am using following regular expression ValidationExpression="[a-zA-Z0-9_. ,'#&$~@!-]*" 为了允许字母数字,空格和某些特殊字符,我使用以下正则表达式ValidationExpression="[a-zA-Z0-9_. ,'#&$~@!-]*"

Now I want to allow double quotes (") as a special character. For this I have tried ValidationExpression="[a-zA-Z0-9_. ,'#&$~@!\\"-]*" 现在,我想允许double quotes (")作为特殊字符。为此,我尝试了ValidationExpression="[a-zA-Z0-9_. ,'#&$~@!\\"-]*" ValidationExpression="[a-zA-Z0-9_. ,'#&$~@!\\"-]*" and ValidationExpression="[a-zA-Z0-9_. ,'#&$~@!"-]*" etc. but gives Parser Error. ValidationExpression="[a-zA-Z0-9_. ,'#&$~@!\\"-]*"ValidationExpression="[a-zA-Z0-9_. ,'#&$~@!"-]*"等,但给出解析器错误。

Can anyone help? 有人可以帮忙吗?

You need to escape " using "" or " 你需要逃离"使用"""

Your regex should be 您的正则表达式应为

^[\w. ,'#&$~@!"-]*$

\\w is similar to [a-zA-Z\\d_] \\w类似于[a-zA-Z\\d_]

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

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