我正在尝试根据下拉列表的选定值验证文本框。基本上我要做的是验证以确保信用卡号以 4 开头,如果选择了 Visa,或者如果选择了万事达卡,则以 5 开头。我还想根据给定的卡片类型验证字符串的长度。这是我到目前为止所拥有的。
<p>
Card Type:* <br />
<asp:DropDownList ID="cardType" runat="server" AutoPostBack="True">
<asp:ListItem>Visa</asp:ListItem>
<asp:ListItem>Mastercard</asp:ListItem>
<asp:ListItem>Amex</asp:ListItem>
</asp:DropDownList>
</p>
<p>
Card Number:* <br />
<asp:TextBox ID="cardNumber" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server"
ErrorMessage="Please enter Card Number" ControlToValidate="cardNumber"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server"
ControlToValidate="cardNumber" validationExpression="^\d+$" ErrorMessage="please only enter numbers"></asp:RegularExpressionValidator>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="cardNumber" ErrorMessage="Please enter correct number"></asp:CustomValidator>
</p>
<p>
Security Code:* <br />
<asp:TextBox ID="securityCode" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server"
ErrorMessage="Please enter Security Code" ControlToValidate="securityCode"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server"
ControlToValidate="securityCode" validationExpression="^\d+$" ErrorMessage="please only enter numbers"></asp:RegularExpressionValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator6" runat="server"
ControlToValidate="securityCode" validationExpression="^\d\d\d?$" ErrorMessage="please only enter three numbers"></asp:RegularExpressionValidator>
</p>
<p>
Expiration Date:* <br />
<asp:TextBox ID="expDate" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server"
ErrorMessage="Please enter Expiration Date" ControlToValidate="expDate"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="dateValidator" runat="server" type="Date" ControlToValidate="expDate" Operator="DataTypeCheck"
ErrorMessage="please enter a valid date (mm/dd/yy)"></asp:CompareValidator>
</p>
<asp:Button ID="btnSubmit" runat="server"
Text="Submit" />