Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET正则表达式-validationExpression_C#_Asp.net_Regex - Fatal编程技术网

C# ASP.NET正则表达式-validationExpression

C# ASP.NET正则表达式-validationExpression,c#,asp.net,regex,C#,Asp.net,Regex,我有一个文本框。我添加了一个正则表达式来验证可以包含一个或20个字符的文本框,如下所示 <asp:RegularExpressionValidator ID="regex" runat="server" ErrorMessage="This contain pipe or more than 20 characters" ValidationExpression="^.{1,20}$" ControlToValidate="txtRegexTester"

我有一个文本框。我添加了一个正则表达式来验证可以包含一个或20个字符的文本框,如下所示

<asp:RegularExpressionValidator ID="regex" runat="server" 
     ErrorMessage="This contain pipe or more than 20 characters"  
     ValidationExpression="^.{1,20}$"
     ControlToValidate="txtRegexTester" >
</asp:RegularExpressionValidator>

我想确保文本框也不包含管道(
|
)符号。我如何在一个
验证表达式中同时实现这两个功能?

类似的功能(除了管道以外的所有功能,1次或20次)


这可能比我的答案有更好的性能!注意:您不需要在字符类中转义
|
"^[^|]{1,20}$"