RegularExpressionValidator检查数字和A-Z

时间:2015-03-19 14:14:49

标签: c# asp.net

HTML

<asp:TextBox ID="txtSasiNo" runat="server" MaxLength="17" Width="250px"></asp:TextBox>
<asp:RegularExpressionValidator CssClass="zorunlu" ValidationGroup="kaskoTeklifSayfasi" Display="Dynamic" ID="rangevalidator1" runat="server" SetFocusOnError="true" ControlToValidate="txtSasiNo" ErrorMessage="Text must be 8 or 17." ValidationExpression="^\d{8}$|^\d{17}$"></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="rfvSasiNo" SetFocusOnError="true" ValidationGroup="kaskoTeklifSayfasi" runat="server" Display="Dynamic" ControlToValidate="txtSasiNo" CssClass="zorunlu">Please Enter Text .</asp:RequiredFieldValidator>

问题:

我有ValidationExpression如下

^\d{8}$|^\d{17}$

这只检查数字的字符数。我如何检查A-Z字符?

1 个答案:

答案 0 :(得分:0)

如果您希望0-9和长度为8或17的A-Z有效:

^[0-9A-Z]{8}$|^[0-9A-Z]{17}$

<强>更新

启用所有字母数字字符0-9,a-z和A-Z使用:

^[0-9A-Za-z]{8}$|^[0-9A-Za-z]{17}$