【问题标题】:Escape character for " in ValidationExpression in ASP.NETASP.NET 中 ValidationExpression 中 " 的转义字符
【发布时间】:2012-04-09 05:09:32
【问题描述】:

我正在使用正则表达式来过滤最终用户输入的无效输入。

在可接受的输入是wordspacedigital. 987654325 @ 987654327 # 987654329 $ 987654331 : 987654333 ' 987654335 ! 987654337 ~ 987654339 | 987654341 ; 987654343 { 987654345 - 987654347 @。结果 下面是我的代码。

<asp:RegularExpressionValidator ID="rgVEditTB1" runat="server" ControlToValidate="txtEditTB1"   
     ValidationExpression="^[\w\s\d\-\.\/\@\,\#\&\$\:\?\"\'\%\!\–\~\|\+\;\”\{\}\-\\]+$"   ErrorMessage="Invalid Special Character"  />

但是,我遇到了在ValidataionExpression 中转义" 的问题,它出错了

Server Tag is not well-formed 错误。

我尝试将转义字符更改为:

\""  
\"   
""   

它也给了我同样的错误。

ValidationExpression 中正确的转义字符应该是什么?

【问题讨论】:

    标签: asp.net regex validation


    【解决方案1】:

    您应该能够传入 HTML 编码值。所以,通过&amp;quot; 就像通过"。像这样的东西:ValidationExpression="^[^&amp;quot;]+$"。在这个正则表达式中,我是说:匹配从字符串开头到结尾的任何字符,而不是引号 (")。

    这同样适用于其他特殊符号。您可以查看here 了解更多编码值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多