0
我想驗證基於選定的下拉列表的值的文本框。基本上我想要做的是驗證以確保信用卡號碼以4開頭,如果選擇簽證或選擇5如果mastercard被選中。我也想根據給定的卡類型驗證字符串的長度。這是我到目前爲止。基於下拉列表選擇驗證文本框
<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" />