Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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
如何使用asp.net正则表达式验证程序限制具有特定格式的文本框_Asp.net_Regex - Fatal编程技术网

如何使用asp.net正则表达式验证程序限制具有特定格式的文本框

如何使用asp.net正则表达式验证程序限制具有特定格式的文本框,asp.net,regex,Asp.net,Regex,我有绑定到asp.net正则表达式验证的文本。我希望字符的最大长度为13,并且希望格式类似于xx/xxxxx-xxxx 这是有效的格式 33/34567-1 33/12345-12 33/12345-123 33/12345-1234 我试过这个 <asp:TextBox ID="txt1" runat="server" OnTextChanged="txt1_TextChanged" class="textNorma

我有绑定到asp.net正则表达式验证的文本。我希望字符的最大长度为13,并且希望格式类似于
xx/xxxxx-xxxx

这是有效的格式

33/34567-1
33/12345-12
33/12345-123
33/12345-1234
我试过这个

<asp:TextBox ID="txt1" runat="server" OnTextChanged="txt1_TextChanged" class="textNormal" MaxLength="13" Width="100"></asp:TextBox> (xx/xxxxx-xxxx)
                    <br />
                    <asp:RegularExpressionValidator ID="regexValidator1" runat="server"
                     ErrorMessage="Must be in format xx/xxxxx-xxxx" ValidationExpression="\d\d\/\d\d\d\d\d-\d{4}$"
                    ControlToValidate="txt1">Must be in format xx/xxxxx-xxxx</asp:RegularExpressionValidator>
(xx/xxxxx-xxxx)

格式必须为xx/xxxxx-xxxxx
但它没有像我想要的那样工作。当我键入
33/45678-12
时,它会抛出验证错误。 必须在
-
之后的最后一部分后面加一个字符


如何解决此问题?

您可以将5位数字缩短为
\d{5}
,并使用
\d{1,4}
匹配结尾处的1-4位数字,该代码仍然具有
MaxLength=“13”


尝试使用
\d\d\/\d{5}-\d{1,4}$
ValidationExpression="\d\d\/\d{5}-\d{1,4}$"